Why doesn't Json.Decode handle arrays in C #?

Can anyone help shed some light on what's going on here?

If I do this in a C # program:

dynamic data = Json.Decode("{\"myObjects\": [ { \"id\": 1 }, { \"id\": 2 } ] }");
int id = data.myObjects[0].id;

      

I can access the id and it is set to 1 ... everything will be fine up to this point.

I don't understand why, when I debug the program, I cannot view the content data

in the locale inspector. Instead, he tells me about it like he doesn't know how to handle the array.

Error There is no additional information about this object

+3


source to share


3 answers


The other answers didn't work for me, but I found an alternative way to view the contents of an array in Visual Studio.

I found that we can see the content DynamicJsonArray

in the Watch window (or IntelliSense) by looking at the Non-Public members of the top-level object. Within this we see a private member _values

and within it we see values. After opening the corresponding value, we see inside the elements Key

and Value

.



We can then go to the opening Value

node and then Results View

which will show the elements in the array. Then we can finally access the individual elements of the collection

enter image description here

+1


source


There seems to be a Visual Studio bug / limitation (at least the 2013 version I am using). If you put the watch on data

, you can click Dynamic View

and see what it has stuff

, but if you click on myObject

(this DynamicJsonArray

), you only get its "dynamic" part, not its "fixed" properties (for example Length

), and if you try click on it Dynamic View

, you get. No further information about this object can be found ... but if you create a clock for data.myObject

then you will still have unusable Dynamic View

, but you can look at the "fixed" properties DynamicJsonArray

(for example Length

) and if you click on the button Result View

you can see the elements of the array. See Image:



enter image description here

+2


source


'data' is declared as a dynamic type and therefore you cannot hover over and see the value. You can still see the value if you add "data" to view.

+1


source







All Articles