【发布时间】:2019-08-09 22:33:29
【问题描述】:
我有以下代码:
var definition = new { result = "", accountinformation = new[] { "" , "" , "" } };
var accountInformationResult = JsonConvert.DeserializeAnonymousType(responseBody, definition);
帐户信息结构作为数组从端点返回,每个元素是另一个包含 3 个字符串的数组。所以嵌入数组不是键值对格式。使用上面的定义 accountinformation 返回 null。这个结构的语法应该是什么?
作为参考,这是 php 端点中发生的事情。
$account_information[] = array( $billing_company, $customer_account_number, $customer_account_manager );
第一行是一个循环。因此是多维数组。
echo json_encode(array('result'=>$result, 'account_information'=>$account_information));
我知道我可以使用动态,但为什么要付出额外的努力?
【问题讨论】:
-
如果您将名称从
accountinformation更改为accountInformation(大写“I”),您能看到会发生什么吗? -
我仍然得到大写 I 的空结果。我确实尝试过 new[][] { "", "", "" } 但那甚至无法编译!
-
还有 account_information?
-
不喜欢下划线。我正在更改其他系统中的代码以删除下划线。在更改代码以便两个系统都使用帐户信息之后,我现在得到了另一个错误。 JsonReaderException:解析值时遇到意外字符:[。路径“accountinformation”,第 1 行,位置 38。我假设这是 new 之后的方括号。
-
查看我的答案,让它在控制台应用程序中工作。
标签: c# arrays definition jsonconvert