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

后端 未结 3 929
长情又很酷
长情又很酷 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 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(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>(sc);
    var myObj = myobjList[0];
    

提交回复
热议问题