douya6229 2016-08-26 06:15
浏览 134
已采纳

将JSON转换为对象

i have a method that sends a POST Request to my PHP API and the API responds with a JSON String return value.

however after using JsonConvert.DeserializeObject() to the JSON result, i am getting this format

{[
  {
    "usr_name": "12-34567",
    "usr_fullname": "LASTNAME, FIRSTNAME MIDDLENAME",
    "usr_emailaddress": "myemail@mail.com",
    "photo_url": "http://mywebsite.com/fetch_photo.php?id=MTItNDA1MDY=",
    "token": "64c420939814c62889ea143d17736841"
  }  
]}

however i am not able to Deserialize it to my Class that is structured like below

public class MyObject
{
    public string usr_name { get; set; }
    public string usr_fullname { get; set; }
    public string usr_emailaddress { get; set; }
    public string photo_url { get; set; }
    public string token { get; set; }
}

i am using Newtonsoft JSON.Net for this purpose, this is my first time dealing with JSON inside C# so i am quite clueless no how or what to do. i've done several research only to find outdated tutorials or questions unlike my returned JSON value

so the php's response looks like this enter image description here

and after trying to deserialize it, it looks like this enter image description here

  • 写回答

3条回答 默认 最新

  • dsdqpdjpq16640651 2016-08-26 06:19
    关注

    Your json string is not valid json - the wrapping {} are invalid. You should check how the json string is generated / encoded inside your php API.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?