小编use*_*770的帖子

将JSON OBJECT转换为JSON ARRAY

这是非常简单的但是很难实现.帮我解决这个问题.

我有一个json数据{"abc":"test","bed":"cot","help":"me"}

我想将上面的jsonObject转换为JSON ARRAY,如[{"abc":"test","bed":"cot","help":"me"}]

JSONObject obj= new JSONObject(str.toString());
Iterator x = obj.keys();
JSONArray jsonArray = new JSONArray();
Map<String, String> map = new HashMap<String, String>();

while (x.hasNext()) {
  for(int i=0;i<obj.length();i++) {
    LOG.info("=============");
    String key = (String) x.next();
    jsonArray.put(obj.get(key));
  }
}
Run Code Online (Sandbox Code Playgroud)

我只得到价值观.请帮我解决这个问题.

java json

1
推荐指数
1
解决办法
2万
查看次数

ES5 风格的连接数组。将数组合并为一个

我必须将数组块与 Angularjs 中的对象数组合并为单个数组。

我的输入数组将是这样的:

[
  [
    {
      "title": "asd",
      "description": "asd"
    },
    {
      "title": "asz",
      "description": "sd"
    }
  ],
  [
    {
      "title": "ws",
      "description": "sd"
    },
    {
      "title": "re",
      "description": "sd"
    }
  ],
  [
    {
      "title": "32",
      "description": "xxs"
    },
    {
      "title": "xxc",
      "description": "11"
    }
  ]
]
Run Code Online (Sandbox Code Playgroud)

上面的输入数组应该像下面的对象数组一样保存

[
  {
    "title": "asd",
    "description": "asd"
  },
  {
    "title": "asz",
    "description": "sd"
  },
  {
    "title": "ws",
    "description": "sd"
  },
  {
    "title": "re",
    "description": "sd"
  },
  {
    "title": "32",
    "description": "xxs"
  }, …
Run Code Online (Sandbox Code Playgroud)

javascript arrays angularjs

0
推荐指数
1
解决办法
1565
查看次数

标签 统计

angularjs ×1

arrays ×1

java ×1

javascript ×1

json ×1