使用java从json String获取值

时间:2016-03-29 10:17:36

标签: java arrays json

[{"statusCode":200,"body":null,"string":"{\"authenticationResultCode\":\"ValidCredentials\",\"brandLogoUri\":\"http:\\\/\\\/dev.virtualearth.net\\\/Branding\\\/logo_powered_by.png\",\"copyright\":\"Copyright © 2016 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.\",\"resourceSets\":[{\"estimatedTotal\":1,\"resources\":[{\"__type\":\"Location:http:\\\/\\\/schemas.microsoft.com\\\/search\\\/local\\\/ws\\\/rest\\\/v1\",\"bbox\":[38.251775282429321,-85.764416391531825,38.259500717570674,-85.751299608468173],\"name\":\"425 W Market St, Louisville, KY 40202\",\"point\":{\"type\":\"Point\",\"coordinates\":[38.255638,-85.757858]},\"address\":{\"addressLine\":\"425 W Market St\",\"adminDistrict\":\"KY\",\"adminDistrict2\":\"Jefferson Co.\",\"countryRegion\":\"United States\",\"formattedAddress\":\"425 W Market St, Louisville, KY 40202\",\"locality\":\"Louisville\",\"postalCode\":\"40202\"},\"confidence\":\"High\",\"entityType\":\"Address\",\"geocodePoints\":[{\"type\":\"Point\",\"coordinates\":[38.255638,-85.757858],\"calculationMethod\":\"Parcel\",\"usageTypes\":[\"Display\"]},{\"type\":\"Point\",\"coordinates\":[38.255367279052734,-85.757896423339844],\"calculationMethod\":\"Interpolation\",\"usageTypes\":[\"Display\",\"Route\"]}],\"matchCodes\":[\"Good\"]}]}],\"statusCode\":200,\"statusDescription\":\"OK\",\"traceId\":\"6bcd334413524cdba8d5c58e85cc1028|HK20271556|02.00.153.400|HK2SCH010280724, HK2SCH010310229\"}"}]

这是我的输入,它是字符串格式的单行值 需要获取所有值(resourceSets标记) 我该如何获得这些价值?

2 个答案:

答案 0 :(得分:0)

尝试使用Gson library ...来自Json的方法,只需要一个POJO。

答案 1 :(得分:0)

您始终可以使用ObjectMapper(jackson库)并将其映射到适合您正在发送的JSON的POJO,或者使用Guava库(检查:JSON parsing using Gson for Java