Integer bufferId = (Integer) map.get("bufferId"); Integer sourceId = (Integer) map.get("sourceId"); String jsonparam = "{\"msg\":\"success\",\"result_type\":\"success\",\"error_level\":false,\"code\":1,\"return_params\":{\"task_buffer_id\":"+bufferId+",\"task_source_id\":"+sourceId+"},\"need_retry\":false,\"error\":false,\"type\":\"amazon_rank\",\"content\":{\"star_list\":{\"four_star\":\"17%\",\"five_star\":\"67%\",\"three_star\":\"8%\",\"first_star\":\"6%\",\"second_star\":\"2%\"},\"ori_review_start\":\"4.4 out of 5 stars\",\"ori_review_text\":\"440 global ratings | 54 global reviews\",\"reviews\":54,\"ratings\":440,\"rank\":{\"Men's Polo Shirts\":\"330\",\"Clothing, Shoes & Jewelry\":\"133326\",\"Men's Novelty Polo Shirts\":\"6\"},\"ori_rank_text\":\"Best Sellers Rank: #133,326 in Clothing, Shoes & Jewelry (See Top 100 in Clothing, Shoes & Jewelry)\\n#6 in Men's Novelty Polo Shirts\\n#330 in Men's Polo Shirts\",\"review_start\":\"4.4\"}}"; JSONObject jsonObject = JSON.parseObject(jsonparam); JSONObject data = jsonObject.getJSONObject("return_params"); JSONObject content = jsonObject.getJSONObject("content"); JSONObject starList = content.getJSONObject("star_list"); JSONObject rank = content.getJSONObject("rank"); System.out.println(jsonObject.toString()); HashMap hashMap = new HashMap(jsonObject).
相当于就是把这个字符串中间的嵌套关系 用json对象再给它装一下。