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

前端 未结 6 1835
遥遥无期
遥遥无期 2020-12-01 12:47

I am trying to read my JSON result.

Here is my RootObject

public class RootObject
{
public int id { get; set; }
public bool is_defau         


        
6条回答
  •  失恋的感觉
    2020-12-01 13:39

    That's because the json you're getting is an array of your RootObject class, rather than a single instance, change your DeserialiseObject to be something like DeserialiseObject (un-tested).

    You'll then have to either change your method to return a collection of RootObject or do some further processing on the deserialised object to return a single instance.

    If you look at a formatted version of the response you provided:

    [
       {
          "id":3636,
          "is_default":true,
          "name":"Unit",
          "quantity":1,
          "stock":"100000.00",
          "unit_cost":"0"
       },
       {
          "id":4592,
          "is_default":false,
          "name":"Bundle",
          "quantity":5,
          "stock":"100000.00",
          "unit_cost":"0"
       }
    ]
    

    You can see two instances in there.

提交回复
热议问题