Cannot deserialize the current JSON array (e.g. [1,2,3]) into type

后端 未结 3 921
长情又很酷
长情又很酷 2020-11-30 08:39

I have a class like this;

public  class MyStok
{
    public int STId { get; set; }
    public int SM { get; set; }
    public string CA { get; set; }
    pub         


        
相关标签:
3条回答
  • 2020-11-30 08:49

    For array type Please try this one.

     List<MyStok> myDeserializedObjList = (List<MyStok>)Newtonsoft.Json.JsonConvert.DeserializeObject(sc), typeof(List<MyStok>));
    

    Please See here for details to deserialise Json

    0 讨论(0)
  • 2020-11-30 09:03
    HttpClient webClient = new HttpClient();
    Uri uri = new Uri("your url");
    HttpResponseMessage response = await webClient.GetAsync(uri)
    var jsonString = await response.Content.ReadAsStringAsync();
    var objData = JsonConvert.DeserializeObject<List<CategoryModel>>(jsonString);
    
    0 讨论(0)
  • 2020-11-30 09:05

    It looks like the string contains an array with a single MyStok object in it. If you remove square brackets from both ends of the input, you should be able to deserialize the data as a single object:

    MyStok myobj = JSON.Deserialize<MyStok>(sc.Substring(1, sc.Length-2));
    

    You could also deserialize the array into a list of MyStok objects, and take the object at index zero.

    var myobjList = JSON.Deserialize<List<MyStok>>(sc);
    var myObj = myobjList[0];
    
    0 讨论(0)
提交回复
热议问题