使用JsonSerializer读写对象

csharp

浏览数:190

2019-1-7

AD:资源代下载服务
string jsonArrayText1 = "[{'a':'a1','b':'b1'},{'a':'a2','b':'b2'}]";
JArray ja = (JArray)JsonConvert.DeserializeObject(jsonArrayText1);
string ja1a = ja[1]["a"].ToString();
//或者
JObject o = (JObject)ja[1];
string oa = o["a"].ToString();
string jsonText = "{\"beijing\":{\"zone\":\"海淀\",\"zone_en\":\"haidian\"}}";
JObject jo = (JObject)JsonConvert.DeserializeObject(jsonText);
string zone = jo["beijing"]["zone"].ToString();
string zone_en = jo["beijing"]["zone_en"].ToString();
    var a = "{\"ext\":\"DT42JNN2LDX8F260DT24P0660T28LLZ0DTT2HH2ZFN80N20DDFX28B4LR8222HBX0H2J2NN684HZR6J8862D0LR24240XJ0V0B02VZ8N2BXPRBRDJP466V0TN0T04648\",\"data\":{\"err_id\":0,\"msg\":\"用户验证失败未绑定\",\"rectify\":\"\",\"url\":\"\",\"ext_code\":1,\"id\":0,\"CustomData\":{\"sessionKey\":\"DT42JNN2LDX8F260DT24P0660T28LLZ0DTT2HH2ZFN80N20DDFX28B4LR8222HBX0H2J2NN684HZR6J8862D0LR24240XJ0V0B02VZ8N2BXPRBRDJP466V0TN0T04648\"}},\"datas\":null,\"msg\":\"用户验证失败未绑定\",\"success\":false,\"url\":null,\"jump\":false}";
    var b = "{\"ext\":null,\"data\":null,\"datas\":null,\"msg\":\"手机号码验证失败\",\"success\":false,\"url\":null,\"jump\":false}";
    JObject jo = (JObject)JsonConvert.DeserializeObject(a);

    var jo1 = JObject.Parse(jo["data"].ToString());     var jo1 = JObject.Parse(string.IsNullOrWhiteSpace(strData) ? "{}" : strData);