我试图解析以下Json字符串
{
{
"data": [
{
"uid": 100001648098091,
"first_name": "Payal",
"last_name": "Sinha",
"sex": "female",
"pic_big_with_logo": "https://m.ak.fbcdn.net/external.ak/safe_image.php?d=AQAi8VLrTMB-UUEs&bust=1&url=https%3A%2F%2Fscontent-a.xx.fbcdn.net%2Fhprofile-ash2%2Fv%2Ft1.0-1%2Fs200x200%2F10018_433988026666130_85247169_n.jpg%3Foh%3Dc2774db94dff4dc9f393070c9715ef65%26oe%3D552CF366&logo&v=5&w=200&h=150",
"username": "payal.sinha.505"
}
]
}
}
我尝试过以下代码
var fb = new FacebookClient(accessToken);
dynamic result = fb.Get("fql",
new { q = "SELECT uid, first_name, last_name, sex, pic_big_with_logo, username FROM user WHERE uid=me()" });
dynamic dynamicJsonResult = JObject.Parse(result);
var userDetail = JsonConvert.DeserializeObject<List<FacebookUserDetailAPIResponseWrapper>>(dynamicJsonResult.data);
类
public class FacebookUserDetails
{
public string username { get; set; }
//Password = EncryptionClass.Md5Hash(Guid.NewGuid().ToString()),
public string first_name { get; set; }
public string last_name { get; set; }
public string sex { get; set; }
public string pic_big_with_log { get; set; }
}
我不确定我做错了但是我使用相同的方法来解析每个json字符串。
提前感谢你。
答案 0 :(得分:0)
var jsonString = @"{
""data"": [
{
""uid"": ""100001648098091"",
""first_name"": ""Payal"",
""last_name"": ""Sinha"",
""sex"": ""female"",
""pic_big_with_logo"": ""https://m.ak.fbcdn.net/external.ak/safe_image.php?d=AQAi8VLrTMB-UUEs&bust=1&url=https%3A%2F%2Fscontent-a.xx.fbcdn.net%2Fhprofile-ash2%2Fv%2Ft1.0-1%2Fs200x200%2F10018_433988026666130_85247169_n.jpg%3Foh%3Dc2774db94dff4dc9f393070c9715ef65%26oe%3D552CF366&logo&v=5&w=200&h=150"",
""username"": ""payal.sinha.505"",
},
]
}";
dynamic userinfo = JValue.Parse(jsonString);
foreach (dynamic userin userinfo.data)
{
Console.WriteLine("\t" + user.uid);
}
IList<FacebookUserDetails> userDeatils = new List<FacebookUserDetails>();
foreach (dynamic userinfoItr in userinfo.data)
{
FacebookUserDetails userdetail= userinfoItr.ToObject<FacebookUserDetails>();
userDeatils.Add(userdetail);
}