1

我有以下 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 中有超过 2 个元素)

到目前为止,我已经写了以下内容:

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"],
                    };

我想限制查询以跳过数组中的第一个对象,但我不知道该怎么做。

4

1 回答 1

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"],
            };
于 2012-08-17T15:07:37.167 回答