在 .NET 中解析 JSON 时出错
Getting Error Whie parsing JSON in .NET
我正在尝试解析以下 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);
class
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 字符串。
提前致谢。
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);
}
我正在尝试解析以下 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);
class
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; }
}
提前致谢。
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);
}