Answer the question
In order to leave comments, you need to log in
How to use json array in C#?
I get this JSON from the server:
{"agent":[{"ID":"1","Surname":"\u0418\u0432\u0430\u043d\u043e\u0432","Name":"\u0418\u0432\u0430\u043d","MiddleName":"\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447","Post":"1"},{"ID":"2","Surname":"testName=tes","Name":"","MiddleName":"\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447","Post":"1"},{"ID":"3","Surname":"test2 Name=test2","Name":"","MiddleName":"\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447","Post":"1"},{"ID":"4","Surname":"test3,Name=test3","Name":"","MiddleName":"\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447","Post":"1"},{"ID":"5","Surname":"test4 , Name=test4","Name":"","MiddleName":"\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447","Post":"1"},{"ID":"6","Surname":"test5 ","Name":"test5","MiddleName":"\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447","Post":"1"}]}
public static void MySQLPreDelAgent()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://dima-n.16mb.com/Okna/PHP/set_all_agent.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
//Console.WriteLine(reader.ReadToEnd());
var temp = (MyArray)JsonConvert.DeserializeObject(reader.ReadToEnd(), typeof(MyArray));
foreach (AllAgent item in temp.items)
{
Console.WriteLine("Key: {0}, Value {1}", item.ID , item.MiddleName);
}
}
}
public class MyArray
{
public List<AllAgent> items { get; set; }
}
public class AllAgent
{
public int ID { get; set; }
public string Surname { get; set; }
public string Name { get; set; }
public string MiddleName { get; set; }
public int Post { get; set; }
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question