RequestJsonAsObject

CSharp · Console

/Program.cs

using System;
using System.Net.Http;
using Newtonsoft.Json;
using System.Collections.Generic;
					
public class Program
{
	public static void Main()
	{
		using(var client = new HttpClient()) 
		{
			string url = "http://210.240.245.13:18080/rest/GetRegData";
			var req = client.GetAsync(url);
			//Console.WriteLine(req.Result.Content.ReadAsStringAsync().Result);
			List<Account> obj = JsonConvert.DeserializeObject<List<Account>>(req.Result.Content.ReadAsStringAsync().Result);
			foreach(var i in obj) 
			{
				Console.WriteLine(i.user_name);
				Console.WriteLine(i.studentID);
				Console.WriteLine(i.password);
				Console.WriteLine(i.phone);
			}
		}
	}
}

public class Account 
{
	public string user_name { get; set; }
	public string studentID { get; set; }
	public string password { get; set; }
	public string phone { get; set; }
}
;