An attempt to method "System.Web.Helpers.Json.Decode (System.String)" to access the field "System.Web.Helpers.Json._serializer" failed

I have the following JSON;

{ "b2c": { "languages": { "de": { "models": { "t300": { "name": "Aveo", "bodyTypes": { "t300-4d-my13": { "trimLevels": { "lt": { "name": "LT", "variants": { "1.2_16V_86_Gas_MT": { "name": "1.2 MT", "price": { "EUR": { "value": 13990, "formatted": "13.990,00 €" } }, "infoFeatures": { "fuel_consumption_extra_urban#consumption": { "name": "Kraftstoffverbrauch außerorts ", "value": "4.6", "formatted": "4,6" }, "top_speed#kilometer_per_hour": { "name": "Höchstgeschwindigkeit", "value": "171", "formatted": "171" } }, "images": null, "documents": null } } } } } } } } } } } } 

Values ​​b2c, de, t300, t300-4d-my13, It, etc. are dynamic, but languages, models, bodyTypes, trimLevels, options, inforFeatures, images and documents will remain the same. I need to extract everything in order to access values ​​like languages. ["De"], models. ["T300"]. Name, timeLevels. ["It"], Options and infoFeatures, since these keys [""] are dynamics, so I'm not sure what to say.

I tried,

  var jsonSerializer = new JsonSerializer(); dynamic dynamicObject = jsonSerializer.Deserialize(new JsonTextReader(new StringReader(jsonString))); //var level1 = dynamicObject.b2c 

I looked it too Disable JSON in a dynamic C # object?

and tried

 var dynamicObject = Json.Decode(jsonString); 

but gets the following error:

An attempt to use the System.Web.Helpers.Json.Decode (System.String) method to access the System.Web.Helpers.Json._serializer field failed.

+4
source share
3 answers

For us, this helped to clear the "Enable Visual Studio Hosting" checkbox on the "Project Properties"> "Debug" tab, from the top answer to Attempt using the "System.Web.Helpers" method. Json..cctor () 'to access the method' System.Web.Helpers.Json.CreateSerializer () 'failed

+3
source

A common solution would be to use something like Json.net and serialize in C # Object - this is very flexible and does not contradict the dynamic nature of the json object coming from the client.

+2
source

This error occurs when you have several projects with different versions of assemblies; for example, if you have JSON.NET 4.5.1 in one project and 5.0.6 in another. Things seem to be sorted if you make sure that the same versions exist everywhere in the solution.

+1
source

Source: https://habr.com/ru/post/1479511/


All Articles