【发布时间】:2015-12-23 16:45:27
【问题描述】:
我需要处理一个包含完整层次结构的对象数组。 Like Country (USA) > State (Texas) > County (Harris) > City > Street (有很多房产)。
我使用了Dictionary<string, dynamic>,但我无法处理任何主要对象的子对象。所以按照上面的例子,Country 处理得很好,但我不知道如何在Country 对象中获取States。
我想处理以下 JSON:
{
"Country": [
{
"Property1": "",
"Property2": "",
"Property3": "",
"Property4": "",
"Property5": "",
"States": [
{ "Prop1": "", "Prop2": "", "Prop3": "", "Prop4": "" },
{ "Prop1": "", "Prop2": "", "Prop3": "", "Prop4": "" }
]
},
{
"Property1": "",
"Property2": "",
"Property3": "",
"Property4": "",
"Property5": "",
"States": [
{ "Prop1": "", "Prop2": "", "Prop3": "", "Prop4": "" },
{ "Prop1": "", "Prop2": "", "Prop3": "", "Prop4": "" }
]
}
]
}
我有以下控制器方法签名:
public ActionResult UploadApplication(List<Dictionary<string, dynamic>> Country)
所有Country 属性都填充得很好,但是当我想访问States 时,它说的是一个对象,无法将其转换为另一个Dictionary<string, dynamic>。
【问题讨论】:
-
请提供您尝试过但不起作用的代码。
-
我有以下控制器方法签名: public ActionResult UploadApplication(List
> Country) 所有 Country 属性都填充得很好,但是当我想访问“States”时据说是一个对象,无法将其转换为另一个 Dictionary -
请编辑您的问题以包含所有所需信息。不要将代码放在 cmets 中。关于 SO 的问题应该是独立的。
-
我能够编辑帖子,抱歉,我不经常使用 stackoverflow。 :)
-
你在使用asp.net-mvc吗?如果是这样,请标记您的问题。另外,您使用的是哪个版本?
标签: c# json asp.net-mvc-4 dictionary