douya6229 2016-08-26 14: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 14: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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器