JSON Can't be Deserialized to Object, Needs Array?

前端 未结 2 890
闹比i
闹比i 2021-01-06 11:35

I am trying to take the incoming JSON items and bind them to listbox items but I am told by visual studio that I need to do an Array and not Object? I\'ve never had to do th

2条回答
  •  执念已碎
    2021-01-06 12:17

    Try this

    RootObject rootObject;
    
    if (json.startsWith("["))
    {
      rootObject = JsonConvert.DeserializeObject>(json)[0];
    }
    else
    {
      rootObject = JsonConvert.DeserializeObject(json);
    }
    

提交回复
热议问题