反序列化json c#获取变量的值

时间:2012-08-22 13:49:19

标签: c# json windows-phone

我使用Newtonsoft JSON DLL反序列化JSON。我有下一个JSON答案

string answer = getjsonnanswer(url);
JObject a = JObject.Parse(answer);

我如何引用a,得到615 - 它在JSON答案中的变量值,但它没有名字。

{
    "response": [615, 
    {
        "body": "Привет) как жизнь?",
        "title": "Re(2): ...",     
        "date": 1268238828,
        "uid": 10024748,
        "mid": 11056,
        "read_state": 0,
        "out":0
    }, 
    {
        "body": "Жду :)",
        "title": "Re(23): ...",
        "date": 1268238448, 
        "uid": 27495120, 
        "mid": 11045,
        "read_state": 1,
        "out":1
    }]
}

2 个答案:

答案 0 :(得分:1)

您只需添加索引器即可从“response”数组中获取第一项:

JObject a = JObject.Parse(answer);

var val = a["response"][0];

答案 1 :(得分:0)

    JObject a = JObject.Parse(answer);


JsonObject a = new JsonObject(answer);
JsonArray ss = (JsonArray)a["response"];
var result = ss[0];