首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态数据解析

动态数据解析
EN

Stack Overflow用户
提问于 2013-12-07 17:44:49
回答 1查看 419关注 0票数 3

我试图使用一个dynamics对象来解析JSON。下面是我正在使用的JSON数据转换器库:https://github.com/cmcdonaldca/shopify.net

以下是我的错误信息:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'string‘不包含“产品”的定义

这是我的JSON:

http://pastebin.com/pnmz7jN0

这是我的代码:

代码语言:javascript
复制
    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,但无法将产品对象放入其中。

EN

回答 1

Stack Overflow用户

发布于 2014-01-29 21:53:07

考虑data[0].title作为开始,但在调试模式下,您应该能够在对象中导航,或者使用即时窗口并运行一些手动查询。

对于错误,您的dynamic data可能只是一个字符串对象,尝试您自己的代码只需删除单词"products“。

代码语言:javascript
复制
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);
    }
}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20444473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档