ASP.NET解析JSON 字符串
请问用Newtonsoft.Json如何解析如下JSON字符串各属性的值?如:serial_number?field_1?created_at?(时间)谢谢,求大神这样的...
请问用 Newtonsoft.Json 如何解析如下JSON字符串各属性的值?
如:serial_number ?
field_1?
created_at ? (时间)
谢谢, 求大神
这样的JSON字符串没有[] 包起来,仔细看看,还是不知道怎么解析,希望方便的话提供一个源码DEMO
{
"form": "RTPppE",
"entry": {
"serial_number": 22,
"field_1": "2014-09-25",
"field_13": "华东区",
"field_14": "xxxx",
"field_15": "xxxxxx",
"field_16": 1,
"field_17": 0,
"field_18": 698,
"field_19": "",
"x_field_weixin_nickname": "",
"x_field_weixin_gender": "",
"x_field_weixin_country": "",
"x_field_weixin_province_city": {},
"x_field_weixin_openid": "oFBGBx6kdOI",
"x_field_weixin_headimgurl": "",
"creator_name": "",
"created_at": "2014-09-25T04:06:07Z",
"updated_at": "2014-09-25T04:06:07Z"
}
}
"form": "TyGOun",
"entry": {
"serial_number": 10,
"field_21": "销售",
"field_22": "2014-09-25",
"field_23": {
"level_1": "xxxx",
"level_2": " 01000"
},
"field_24": 1,
"field_25": 798,
"field_26": "",
"field_27": "",
"x_field_weixin_nickname": "",
"x_field_weixin_gender": "",
"x_field_weixin_country": "",
"x_field_weixin_province_city": {},
"x_field_weixin_openid": "",
"x_field_weixin_headimgurl": "",
"creator_name": "",
"created_at": "2014-09-25T07:13:06Z",
"updated_at": "2014-09-25T07:13:06Z"
}
} 展开
如:serial_number ?
field_1?
created_at ? (时间)
谢谢, 求大神
这样的JSON字符串没有[] 包起来,仔细看看,还是不知道怎么解析,希望方便的话提供一个源码DEMO
{
"form": "RTPppE",
"entry": {
"serial_number": 22,
"field_1": "2014-09-25",
"field_13": "华东区",
"field_14": "xxxx",
"field_15": "xxxxxx",
"field_16": 1,
"field_17": 0,
"field_18": 698,
"field_19": "",
"x_field_weixin_nickname": "",
"x_field_weixin_gender": "",
"x_field_weixin_country": "",
"x_field_weixin_province_city": {},
"x_field_weixin_openid": "oFBGBx6kdOI",
"x_field_weixin_headimgurl": "",
"creator_name": "",
"created_at": "2014-09-25T04:06:07Z",
"updated_at": "2014-09-25T04:06:07Z"
}
}
"form": "TyGOun",
"entry": {
"serial_number": 10,
"field_21": "销售",
"field_22": "2014-09-25",
"field_23": {
"level_1": "xxxx",
"level_2": " 01000"
},
"field_24": 1,
"field_25": 798,
"field_26": "",
"field_27": "",
"x_field_weixin_nickname": "",
"x_field_weixin_gender": "",
"x_field_weixin_country": "",
"x_field_weixin_province_city": {},
"x_field_weixin_openid": "",
"x_field_weixin_headimgurl": "",
"creator_name": "",
"created_at": "2014-09-25T07:13:06Z",
"updated_at": "2014-09-25T07:13:06Z"
}
} 展开
3个回答
展开全部
创建一个类 Test 属性form 属性entry 对象
entry对象:属性serial_number 属性...
就是这个样子,根据需求来进行解析
entry对象:属性serial_number 属性...
就是这个样子,根据需求来进行解析
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你加一个 [], 包起来不就能解析成 List 了
/// <summary>
/// 转换为JSON字符串
/// </summary>
public static string JsonSerializeByNewton<T>(T obj)
{
if (obj == null)
return "";
StringWriter sw = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
json.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
using (Newtonsoft.Json.JsonWriter jw = new Newtonsoft.Json.JsonTextWriter(sw))
{
json.Serialize(jw, obj);
}
return sw.ToString();
}
public static T JsonDeserializeByNewton<T>(string jsonStr) where T : class
{
Newtonsoft.Json.JsonSerializer jSeri = new Newtonsoft.Json.JsonSerializer();
using (StringReader sr = new StringReader(jsonStr))
{
return (T)jSeri.Deserialize(sr, typeof(T));
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把字符串转成json对象
$.parseJSON
$.parseJSON
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询