【问题标题】:How to parse Json data from HttpResponse如何从 HttpResponse 解析 Json 数据
【发布时间】:2015-12-07 16:15:12
【问题描述】:

我要解析Json响应:

client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);

有什么建议吗?

【问题讨论】:

标签: java json


【解决方案1】:

你可以使用 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/

【讨论】:

    猜你喜欢
    • 2011-02-20
    • 2012-10-03
    • 2023-03-27
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    相关资源
    最近更新 更多