【发布时间】:2014-10-08 07:11:33
【问题描述】:
我真的很困惑为什么我无法访问我从Json 字符串反序列化的任何数据。当我逐步完成该过程时,我可以看到数据在那里,但我无法访问它。
我将数据放入Dictionary<string, object>,它的Count 为2。它包含object{object[]}(我将其读作objects 的ArrayList?)和一个带有响应信息的object。
对于访问ArrayList 中的对象所需的响应信息,我并不太在意。我没有这样的运气,我的代码如下:
var output = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(await response.Content.ReadAsStringAsync());
我尝试使用output["List"](列表是对象键)仅获取ArrayList,并且仍然可以看到里面的所有对象,但仍然无法访问它们。这可能是一个简单的解决方法,总是如此,但我整天都在盯着这个问题,只是无法理解它,所以可以用另一双眼睛来解决。
谢谢
编辑
Json 字符串格式如下:
{"List":[{"Id":1,"intProperty":2,"boolProperty":false},{"Id":2,"intProperty":3,"boolProperty":false},{"Id":4,"intProperty":5,"boolProperty":false}],"ResponseInformation":{Other info here}}
【问题讨论】:
-
你能显示你正在使用的 JSON 字符串吗?
-
现在已经完成,在我发布后才意识到.. 已经取出数据,但我猜这并不重要
-
您是否尝试过反序列化为
Dictionary<string, object[]>? -
我已经尝试过
Dictionary<string[], object>但不是那样...我会尝试... -
InnerException {"No parameterless constructor defined for type of 'System.Object[]'."} System.Exception {System.MissingMethodException}不 :(
标签: c# json api serialization arraylist