Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Unassigned: Bug: JSON.Decode -> modify object -> Encode.. ignores the array value [1574]

$
0
0
Consider the following code:

```c#
dynamic dObj = System.Web.Helpers.Json.Decode ( contentsOfJsonFile );

// where:

dObj.title // is string
dObj.description // is string
dObj.tags // is an array! ["videos", "pictures", "other assets"]
```

Now, if we access dObj.tags[0] it returns string value. But if we do:

```c#
Json.Encode( dObj )
```

it will convert the object back to JSON string, except the arrays (tags). Apparently, there is a BUG with nested array scenario.

<b>
In other words:

```c#
jsonString != Encode( Decode( jsonString ) )
```

*where at atleast one field of JSON has array value.*
</b>
For instance, after decoding, encoding this object:

```json
{
"version":3,
"file":"respond.min.js",
"lineCount":1,
"mappings":"CAAM",
"sources":["respond.js"],
"names":["window","matchMedia","doc","bool","docElem"]
}
```

the values of "sources" and "names" will be lost by `Encode()`.

The same works with JSON.NET (third party newtonking library). I guess [here is the code](https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/Serialization/JsonDynamicContract.cs#L86-L104) to unpack the dynamic object in JSON.NET.

Please fix this issue with the native `System.Web.Helpers.Json.Encode()` method.

Thank you.



Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>