C# Json数据解析
作者:互联网
public static void Main(string[] args)
{
List<Text> cc = new List<Text>();
string jsonArrayText1 = "[{'a':'a1','b':'b1'},{'a':'a2','b':'b2'}]";//json数组
//解析json数组
JArray ja = (JArray)JsonConvert.DeserializeObject(jsonArrayText1);
Console.WriteLine(ja.Count);
for (int i = 0; i < ja.Count; i++)
{
Text text = new Text();
text.MyProperty = ja[i]["a"].ToString();
text.MyPropertys = ja[i]["b"].ToString();
cc.Add(text);
}
string jsonText = @"{""p_code"" : ""1234"",""code_id"" : ""123456""}";//json数据
//解析json数据
JObject jo = (JObject)JsonConvert.DeserializeObject(jsonText);
var cMarCode = jo["p_code"].ToString();
var cWhCode = jo["code_id"].ToString();
}
public class Text {
public string MyProperty { get; set; }
public string MyPropertys { get; set; }
}
标签:code,string,C#,text,json,public,Json,解析,ja 来源: https://blog.csdn.net/weixin_45381269/article/details/113913844