0
public class information
{
     public string name { get; set; }
     public string surname { get; set; }
}
public class JsonFormat
{
     public IList<information> information { get; set; }
}
protected void gettextbox_Click(object sender, EventArgs e)
{
     JsonFormat newjson = new JsonFormat();
     List<information> p = new List<information>();
     information add1 = new information { name = textbox1.Text , surname = textbox2.Text };
     information add2 = new information { name = textbox3.Text, surname = textbox4.Text };
     p.Add(add1);
     p.Add(add2);
     newjson.information = p;
     string json = JsonConvert.SerializeObject(newjson);
}

string json here :

"{\"information\":[{\"name\":\"data1\",\"surname\":\"data2\"}, \"name\":\"data3\",\"surname\":\"data4\"}]}"

it's okay here but, how can I deserialize the data on the list? Thank you in advance for your help.

JosephRT
  • 545
  • 4
  • 19
f.ulas
  • 11
  • 2
  • 1
    Possible duplicate of [Deserializing JSON data to C# using JSON.NET](https://stackoverflow.com/questions/2546138/deserializing-json-data-to-c-sharp-using-json-net) – Camilo Terevinto Jul 30 '18 at 16:45

1 Answers1

0
List<information> informationList = JsonConvert.DeserializeObject<List<information>>(json);

https://www.newtonsoft.com/json/help/html/DeserializeObject.htm

Mohsin Mehmood
  • 4,156
  • 2
  • 12
  • 18
  • okay, information information = JsonConvert.DeserializeObject(json); information.name --> which income, data1 or data3 ? – f.ulas Jul 30 '18 at 16:31
  • I noticed that you have list of information objects so you have to de-serialize to List – Mohsin Mehmood Jul 30 '18 at 16:34
  • Also, instead of directly serializing the list of information why you are doing `newjson.information = p;` and then `string json = JsonConvert.SerializeObject(newjson);` – Mohsin Mehmood Jul 30 '18 at 16:41