从JSON数组中获取字符串?

时间:2016-01-31 11:27:52

标签: java android arrays json

我正在尝试使用此方法从JSON数组获取gadgetry_thumbnail_image路径,但返回null:

JSONObject custom_fields = postObject.getJSONObject("custom_fields");
 String thumbpath = custom_fields.optString("gadgetry_thumbnail_image");

这是JSON数组:

{"posts":[{"custom_fields":{"gadgetry_post_viewed":["12"],"gadgetry_tfuse_post_options":["a:58:{s:22:\"gadgetry_disable_image\";s:5:\"false\";s:22:\"gadgetry_disable_video\";s:5:\"false\";s:26:\"gadgetry_disable_post_meta\";s:5:\"false\";s:23:\"gadgetry_disable_author\";s:5:\"false\";s:31:\"gadgetry_disable_published_date\";s:5:\"false\";s:24:\"gadgetry_disable_coments\";s:5:\"false\";s:28:\"gadgetry_disable_author_info\";s:5:\"false\";s:19:\"gadgetry_page_title\";s:13:\"default_title\";s:21:\"gadgetry_custom_title\";s:0:\"\";s:21:\"gadgetry_single_image\";s:0:\"\";s:30:\"gadgetry_single_img_dimensions\";a:2:{i:0;s:3:\"320\";i:1;s:3:\"250\";}s:28:\"gadgetry_single_img_position\";s:10:\"alignright\";s:24:\"gadgetry_thumbnail_image\";s:104:\"http:\/\/www.mysite.com\/wp-content\/uploads\/2015\/11\/11666271_761774897268291_544140090628098983_n.jpg\";s:27:\"gadgetry_thumbnail_position\";s:7:\"noalign\";s:19:\"gadgetry_video_link\";s:0:\"\";s:25:

这是完整的数组

{"custom_fields":{"gadgetry_post_viewed":["4"],"gadgetry_tfuse_post_options":["a:58:{s:22:\"gadgetry_disable_image\";s:5:\"false\";s:22:\"gadgetry_disable_video\";s:5:\"false\";s:26:\"gadgetry_disable_post_meta\";s:5:\"false\";s:23:\"gadgetry_disable_author\";s:5:\"false\";s:31:\"gadgetry_disable_published_date\";s:5:\"false\";s:24:\"gadgetry_disable_coments\";s:5:\"false\";s:28:\"gadgetry_disable_author_info\";s:5:\"false\";s:19:\"gadgetry_page_title\";s:13:\"default_title\";s:21:\"gadgetry_custom_title\";s:0:\"\";s:21:\"gadgetry_single_image\";s:0:\"\";s:30:\"gadgetry_single_img_dimensions\";a:2:{i:0;s:3:\"320\";i:1;s:3:\"250\";}s:28:\"gadgetry_single_img_position\";s:10:\"alignright\";s:24:\"gadgetry_thumbnail_image\";s:104:\"http:\/\/www.mystite.rs\/wp-content\/uploads\/2015\/11\/11666271_761774897268291_544140090628098983_n.jpg\";s:27:\"gadgetry_thumbnail_position\";s:7:\"noalign\";s:19:\"gadgetry_video_link\";s:0:\"\";s:25:\"gadgetry_video_dimensions\";a:2:{i:0;s:3:\"590\";i:1;s:3:\"191\";}s:23:\"gadgetry_video_position\";s:9:\"alignleft\";s:23:\"gadgetry_header_element\";s:7:\"without\";s:22:\"gadgetry_select_slider\";s:2:\"-1\";s:17:\"gadgetry_page_map\";s:0:\"\";s:25:\"gadgetry_content_ads_post\";s:4:\"true\";s:21:\"gadgetry_top_ad_space\";s:5:\"false\";s:21:\"gadgetry_top_ad_image\";s:0:\"\";s:19:\"gadgetry_top_ad_url\";s:0:\"\";s:23:\"gadgetry_top_ad_adsense\";s:0:\"\";s:28:\"gadgetry_bfcontent_ads_space\";s:5:\"false\";s:23:\"gadgetry_bfcontent_type\";s:5:\"image\";s:25:\"gadgetry_bfcontent_number\";s:3:\"one\";s:29:\"gadgetry_bfcontent_ads_image1\";s:0:\"\";s:27:\"gadgetry_bfcontent_ads_url1\";s:0:\"\";s:31:\"gadgetry_bfcontent_ads_adsense1\";s:0:\"\";s:29:\"gadgetry_bfcontent_ads_image2\";s:0:\"\";s:27:\"gadgetry_bfcontent_ads_url2\";s:0:\"\";s:31:\"gadgetry_bfcontent_ads_adsense2\";s:0:\"\";s:29:\"gadgetry_bfcontent_ads_image3\";s:0:\"\";s:27:\"gadgetry_bfcontent_ads_url3\";s:0:\"\";s:31:\"gadgetry_bfcontent_ads_adsense3\";s:0:\"\";s:29:\"gadgetry_bfcontent_ads_image4\";s:0:\"\";s:27:\"gadgetry_bfcontent_ads_url4\";s:0:\"\";s:31:\"gadgetry_bfcontent_ads_adsense4\";s:0:\"\";s:29:\"gadgetry_bfcontent_ads_image5\";s:0:\"\";s:27:\"gadgetry_bfcontent_ads_url5\";s:0:\"\";s:31:\"gadgetry_bfcontent_ads_adsense5\";s:0:\"\";s:29:\"gadgetry_bfcontent_ads_image6\";s:0:\"\";s:27:\"gadgetry_bfcontent_ads_url6\";s:0:\"\";s:31:\"gadgetry_bfcontent_ads_adsense6\";s:0:\"\";s:29:\"gadgetry_bfcontent_ads_image7\";s:0:\"\";s:27:\"gadgetry_bfcontent_ads_url7\";s:0:\"\";s:31:\"gadgetry_bfcontent_ads_adsense7\";s:0:\"\";s:19:\"gadgetry_hook_space\";s:5:\"false\";s:19:\"gadgetry_hook_image\";s:0:\"\";s:17:\"gadgetry_hook_url\";s:0:\"\";s:21:\"gadgetry_hook_adsense\";s:0:\"\";s:25:\"gadgetry_content_subtitle\";s:0:\"\";s:20:\"gadgetry_content_top\";s:0:\"\";s:23:\"gadgetry_content_bottom\";s:0:\"\";s:18:\"gadgetry_seo_title\";s:0:\"\";s:24:\"gadgetry_seo_description\";s:0:\"\";}"]}

1 个答案:

答案 0 :(得分:0)

您提供的“数组”不完整。它有一个未闭合的字符串。