我试图使用一个dynamics对象来解析JSON。下面是我正在使用的JSON数据转换器库:https://github.com/cmcdonaldca/shopify.net
以下是我的错误信息:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'string‘不包含“产品”的定义
这是我的JSON:
http://pastebin.com/pnmz7jN0
这是我的代码:
public void GetProducts()
{
// The JSON Data Translator will automatically decode the JSON for you
dynamic data = _api.Get("/admin/products.json");
// the dynamic object will have all the fields just like in the API Docs
foreach (var product in data.products)
{
Console.Write(product.title);
}
}我尝试过data.products和data,但无法将产品对象放入其中。
发布于 2014-01-29 21:53:07
考虑data[0].title作为开始,但在调试模式下,您应该能够在对象中导航,或者使用即时窗口并运行一些手动查询。
对于错误,您的dynamic data可能只是一个字符串对象,尝试您自己的代码只需删除单词"products“。
public void GetProducts()
{
// The JSON Data Translator will automatically decode the JSON for you
dynamic data = _api.Get("/admin/products.json");
// the dynamic object will have all the fields just like in the API Docs
foreach (var product in data) //here is the change from the code you posted
{
Console.Write(product.title);
}
}

https://stackoverflow.com/questions/20444473
复制相似问题