2012-08-17 107 views
1

我有以下的JSON的JSON的选择:LINQ到某些元素

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

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

+1

我不明白'创建限制'是什么意思。你能解释一下你的问题吗? – 2012-08-17 13:47:06

+0

我的意思是如何跳过数组中的第一个对象 - 数字型 (以及所有数据的长期) – chromigo 2012-08-17 15:22:16

回答

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

这正是我想要的。谢谢! – chromigo 2012-08-17 15:17:00