如何从c# Visual Studio中使用JSON字符串到对象方法的对象中获取信息?
string jsonStr = "[{'Name':'John Simith','Age':35},{'Name':'Pablo Perez','Age':'34'}]";
JavaScriptSerializer jsss = new JavaScriptSerializer();
objectstrPDItem = jsss.Deserialize(jsonStr, typeof(object));
如何获取objectstrPDItem
的信息?
尝试使用Newtonsoft。Json
List<Person> persons = JsonConvert.DeserializeObject<List<Person>>(jsonStr);
类
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
测试foreach (var person in persons) Console.WriteLine($"({person.Name},{person.Age})");
输出(John Simith,35)
(Pablo Perez,34)
这对我来说很有用:https://forums.asp.net/t/2099529.aspx?Decoding +的+ json使用json + + +数据+不+净
JArray jsonVal = JArray.Parse(jsonStr) as JArray;
dynamic albumsjsonVal = jsonValDenis;
foreach (dynamic album in albumsjsonVal)
{
var test = album.id;
var testname = album.name;
//Response.Write(album.id + " -- " + album.paymentDue + " <br />");
}