我想解析Json
回复:
client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
有任何建议如何做到这一点?
答案 0 :(得分:2)
你可以使用json-simple
https://code.google.com/p/json-simple/
如果你使用maven
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
然后在你的代码中
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
// get a String from the JSON object
String firstName = (String) jsonObject.get("firstname");
System.out.println("The first name is: " + firstName);
这里有一个例子
http://examples.javacodegeeks.com/core-java/json/java-json-parser-example/