JSON deserialization against a JSON which has nested array property
950 Views
8 Comments
Solved
Question

Hello,

I have a problem on JSON deserialization.
I get the problem by following procedure.

  1. Create a structure by using 'Add structure from JSON' with following JSON text.
    {
        "answers": [
                "0.12",
                "20.12"
    }
    Note that this is a simplified JSON from my project's much more complicated JSON.
  2. Use JSON Deserialize tool with the structure created step 1 in action flow.
  3. To run the action with JSON text shown in step 1.
  4. The error message below will appear.
    Failed to deserialize JSON to MyAnswer:
    Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ssSvgDesignViewer.RestRecords.JSONSTAnswerItemStructure' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
    To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
    Path 'answers[0]', line 3, position 9.


My environment info:

  • Personal Environment 11.0.118.0
  • Service Studio 11.0.406.0

Could anyone help me?

Best regards,
Moriya Takasi