【问题标题】:JSON Array parsing through iterator [duplicate]通过迭代器解析JSON数组[重复]
【发布时间】:2018-05-28 05:57:03
【问题描述】:

我有一个json array 像这样-:

"custom_attributes": [
            {
                "attribute_code": "description",
                "value": "Darkly sophisticated aromas take you into Siberia"},
            {
                "attribute_code": "color",
                "value": "6"
            },
            {
                "attribute_code": "options_container",
                "value": "container2"
            },
            {
                "attribute_code": "required_options",
                "value": "0"
            },
            {
                "attribute_code": "gift_message_available",
                "value": "2"
            },
            {
                "attribute_code": "brand",
                "value": "Molton Brown "
            },
            {
                "attribute_code": "supplier",
                "value": "Molton Brown "
            },
            {
                "attribute_code": "features",
                "value": "Twilight "
            }
        ]

我想通过iterator解析它。我的键是attribute_code 和值。

请帮我解析一下。

【问题讨论】:

  • 请展示你的作品。 JSON 无效
  • @IntelliJAmiya JSON 有效。这是一个具有相同键的数组。我想得到,假设是“描述”。我不想像 getJsonObject(0) 那样写。相反,我希望迭代器找到 attr 代码“描述”及其具体值
  • 只写一个for循环。这正是迭代的含义。
  • 离开我已经通过HashMap完成了

标签: android arrays json iterator


【解决方案1】:

您的 JSON 无效。它应该以 [ 开头,因此只需删除用于 json 数组的键“custom_attributes”。

【讨论】:

  • 我想在数组内部进行迭代。忽略什么是自定义数组。
  • 离开我已经通过HashMap完成了
  • 其实问题不在于迭代,你在这里发布的json是无效的,你可以从codebeautify.org/jsonviewer检查,你首先需要制作一个有效的json,然后你就可以迭代那个json数组.
猜你喜欢
  • 2012-07-09
  • 2014-07-01
  • 2016-10-24
  • 1970-01-01
  • 1970-01-01
  • 2013-08-04
  • 1970-01-01
  • 2016-03-28
  • 1970-01-01
相关资源
最近更新 更多