我使用
调用facebook营销APIHttpResponse response = httpclient.execute(httpget);
String resp1 = EntityUtils.toString(response.getEntity());
JsonNode jsonNode = mapper.readTree(resp1).get("data").get("insights");
但这是空的。 我怎样才能得到: 获得( “数据”)获得( “见解”),获得( “数据”);
我的json:
{"data":[{"insights":{"data":[{"ad_name":"Default name - ","campaign_name":"Campaign name","impressions":"67067","spend":"219.66","date_start":"2016-12-25","date_stop":"2017-01-23"}],"paging":{"cursors":{"before":"MAZDZD","after":"MAZDZD"}}},"adcreatives":{"data":[{"image_hash":"669a414c6843bbf0f59555","id":"640513"}]},"id":"606513"},{"adcreatives":{"data":[{"image_hash":"06e781e7a3959f79977ccd1a","id":"60675513"}]},"id":"005113"},{"adcreatives":{"data":[{"image_hash":"3dcdc68a83a49e747a980c9744cd","id":"6060334487513"}]},"id":"6060334106913"},{"insights":{"data":[{"ad_name":"Default other name ","campaign_name":"other campaign 2016","impressions":"70377","spend":"146.08","date_start":"2016-12-25","date_stop":"2017-01-23"}],"paging":{"cursors":{"before":"MAZDZD","after":"MAZDZD"}}},"adcreatives":{"data":[{"image_hash":"5d59834d2de12e32a98f4f34","id":"6057313"}]},"id":"6049313"},{"adcreatives":{"data":[{"id":"6053989151913"}]},"id":"6052610974313"},{"adcreatives":{"data":[{"image_hash":"a92ecf5dbd0e6031d1351a0f3","id":"9112313"}]},"id":"2611813"},{"adcreatives":{"data":[{"image_hash":"60f2c2a93ea87ae341e40a65c231","id":"6051007278713"}]},"id":"6047010497313"},{"adcreatives":{"data":[{"image_hash":"60f2c2a93ea87ae3411bb3e40a65c231","id":"6051007153513"}]},"id":"6047010216113"},{"adcreatives":{"data":[{"image_hash":"3c9bcfad7c7356fa8481c054ed7481dc","id":"6047616979313"}]},"id":"6047616946713"},{"adcreatives":{"data":[{"image_hash":"3c9bcfad7c7356fa8481c054ed7481dc","id":"6047614347513"}]},"id":"6044762761713"},{"adcreatives":{"data":[{"image_hash":"95a61fdf9517ebb866621c8453e2b2b2","id":"6042650860113"}]},"id":"6042650755513"},{"adcreatives":{"data":[{"image_hash":"d2744c1d83400274b66b9ad47a1d08a1","id":"6047010305713"}]},"id":"6047010307513"},{"adcreatives":{"data":[{"image_hash":"95a61fdf9517ebb866621c8453e2b2b2","id":"6042650553313"}]},"id":"6042644920313"},{"adcreatives":{"data":[{"image_hash":"d2744c1d83400274b66b9ad47a1d08a1","id":"6047010113113"}]},"id":"6047010115113"},{"adcreatives":{"data":[{"image_hash":"6985e85b984ade3d2d1bf53186b7e193","id":"6039910059713"}]},"id":"6039910061913"},{"adcreatives":{"data":[{"image_hash":"c374a02c47b560c74c7212082a2b1481","id":"6041195637313"}]},"id":"6041195638713"},{"adcreatives":{"data":[{"image_hash":"982bfc91882ed3e4823d4d8023648a9e","id":"6038613772313"}]},"id":"6038613773713"},{"adcreatives":{"data":[{"image_hash":"08fbef4f934fbe1d834d6fb41d73e8a1","id":"6038613139513"}]},"id":"6038613184913"}],"paging":{"cursors":{"before":"NjA2MDY0MDA5NzUxMwZDZD","after":"NjAzODYxMzE4NDkxMwZDZD"}}}
答案 0 :(得分:0)
您可以通过以下代码从json字符串中删除代码来获取数据数组
JSONObject reader = new JSONObject(input_json_string);
JsonArray data=reader.getJsonArray("data").getJSONObject("insights").getJSONArray("data");
for(int i=0;i<data.length;i++)