0

我对 jsonobject 有问题,我想从 jsonobject(位置)中检索属性“名称”,它也是 jsonobject(朋友)的属性。这是我的动态变量朋友

   friend = {"id":"100001867845514","name":"ucef nahs","location": {"id":"100245266683893","name":"settat, Casablanca, Morocco"}, "picture":"http://profile.ak.fbcdn.net/hprofile-ak-snc4/49453_100001867845514_620239062_q.jpg"}

可以检索位置的属性名称

4

1 回答 1

1
        var jss = new JavaScriptSerializer();
        var ob = jss.Deserialize<Dictionary<string, object>>(
                "{\"id\":\"100001867845514\",\"name\":\"ucef nahs\",\"location\": {\"id\":\"100245266683893\",\"name\":\"settat, Casablanca, Morocco\"}, \"picture\":\"http://profile.ak.fbcdn.net/hprofile-ak-snc4/49453_100001867845514_620239062_q.jpg\"}");
        var location = ob.FirstOrDefault(friend => friend.Key == "location").Value as IDictionary<string, object>;
        if (location != null)
        {
            var locationName = location.FirstOrDefault(elem => elem.Key == "name").Value;
            Console.WriteLine(locationName);
            Console.ReadLine();
        }
于 2012-05-19T17:05:01.397 回答