{"id":475,"date":"2016-12-23T15:40:46","date_gmt":"2016-12-23T14:40:46","guid":{"rendered":"https:\/\/mokrzycki.eu\/blog\/?p=475"},"modified":"2018-12-04T10:18:58","modified_gmt":"2018-12-04T09:18:58","slug":"mergeconcatenate-jsonobjects","status":"publish","type":"post","link":"https:\/\/mokrzycki.eu\/blog\/2016\/12\/23\/mergeconcatenate-jsonobjects\/","title":{"rendered":"Merge\/concatenate jsonObjects"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">public static JSONObject concat(@NonNull JSONObject[] objs) {\r\n        ArrayList&lt;JSONObject&gt; jsonObjectArrayList = new ArrayList&lt;&gt;();\r\n\r\n        for (JSONObject o : objs) {\r\n            if (o.length() &gt; 0) {\r\n                jsonObjectArrayList.add(o);\r\n            }\r\n        }\r\n\r\n        JSONObject merged = new JSONObject();\r\n        JSONObject[] jsonObjects = jsonObjectArrayList.toArray(\r\n                new JSONObject[jsonObjectArrayList.size()]);\r\n        for (JSONObject obj : jsonObjects) {\r\n            Iterator it = obj.keys();\r\n            while (it.hasNext()) {\r\n                String key = (String) it.next();\r\n                Object value = null;\r\n\r\n                try {\r\n                    value = obj.get(key);\r\n                } catch (JSONException e) {\r\n                    e.printStackTrace();\r\n                }\r\n\r\n                try {\r\n                    merged.put(key, value);\r\n                } catch (JSONException e) {\r\n                    e.printStackTrace();\r\n                }\r\n            }\r\n        }\r\n\r\n        return merged;\r\n    }<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>public static JSONObject concat(@NonNull JSONObject[] objs) { ArrayList&lt;JSONObject&gt; jsonObjectArrayList = new ArrayList&lt;&gt;(); for (JSONObject o&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[500],"tags":[122,345,344,343],"_links":{"self":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/475"}],"collection":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/comments?post=475"}],"version-history":[{"count":1,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":476,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions\/476"}],"wp:attachment":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/categories?post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/tags?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}