尝试通过方法'System.Web.Helpers.Json.Decode(System.String)'访问字段'System.Web.Helpers.Json._serializer'失败 [英] Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed
问题描述
我有以下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
}
}
}
}
}
}
}
}
}
}
}
}
b2c,de,t300,t300-4d-my13等是动态的,但语言,模型,bodyType,trimLevels,变体,inforFeatures,图像和文档将保持不变。
我需要提取所有内容以访问值,例如语言。[ de],模型。[ t300]。name,timeLevels。[ It],变量和infoFeatures,作为这些键[]是动态的,所以我不确定要参考什么。
The values of b2c, de, t300, t300-4d-my13, It etc.. are dynamic but languages, models, bodyTypes, trimLevels, variants, inforFeatures, images and documents would remain same. I need to extract all to access values like languages.["de"], models.["t300"].name, timeLevels.["It"], Variants and infoFeatures, as these keys [""] are dynamics so I am not sure what to refer.
我已经尝试过,
var jsonSerializer = new JsonSerializer();
dynamic dynamicObject = jsonSerializer.Deserialize(new JsonTextReader(new StringReader(jsonString)));
//var level1 = dynamicObject.b2c
我也已经看过了b 将JSON反序列化为C#动态对象吗?
并尝试了
var dynamicObject = Json.Decode(jsonString);
但收到以下错误;
尝试通过方法'System.Web.Helpers.Json.Decode(System.String)'访问字段'System.Web.Helpers.Json._serializer'。
Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed.
推荐答案
对于我们来说,它有助于从顶部答案中取消选中项目属性>调试选项卡中的启用Visual Studio托管过程。到通过方法'System尝试.Web.Helpers.Json..cctor()访问方法 System.Web.Helpers.Json.CreateSerializer()失败
For us it helped to uncheck "Enable the Visual Studio hosting process" in the Project properties > Debug tab, from the top answer to Attempt by method 'System.Web.Helpers.Json..cctor()' to access method 'System.Web.Helpers.Json.CreateSerializer()' failed
这篇关于尝试通过方法'System.Web.Helpers.Json.Decode(System.String)'访问字段'System.Web.Helpers.Json._serializer'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!