我有以下JSON:
{"response":[2939,
{"mid":6581,"date":1345018696,"out":0,"uid":84175314,"read_state":1,"title":" ... ","body":"Text1"},
{"mid":6578,"date":1344984256,"out":0,"uid":32438192,"read_state":1,"title":" ... ","body":"Text2"}
]}
使用Newtonsoft JSON库,我只需选择此部分(然后将数据添加到我的对象)
{"mid":6581,"date":1345018696,"out":0,"uid":84175314,"read_state":1,"title":" ... ","body":"Text1"},
{"mid":6578,"date":1344984256,"out":0,"uid":32438192,"read_state":1,"title":" ... ","body":"Text2"}
(源JSON中有两个以上的元素)
到目前为止,我写了以下内容:
JObject jRes = JObject.Parse(json);
JArray jAr = (JArray)jRes["response"];
var query =
from msg in jAr
select new
{
mid = (int)jAr["mid"],
date = (int)jAr["date"],
outt = (short)jAr["out"],
uid = (int)jAr["uid"],
read_state = (short)jAr["read_state"],
title = (string)jAr["title"],
body = (string)jAr["body"],
};
我想将查询限制为跳过数组中的第一个对象,但我不知道该怎么做。
答案 0 :(得分:1)
var query = from msg in jAr
where !(msg is JValue)
select new
{
mid = (int)msg["mid"],
date = (int)msg["date"],
outt = (short)msg["out"],
uid = (int)msg["uid"],
read_state = (short)msg["read_state"],
title = (string)msg["title"],
body = (string)msg["body"],
};