Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 打印json响应值_Java_Json - Fatal编程技术网

Java 打印json响应值

Java 打印json响应值,java,json,Java,Json,我已经使用unirest调用了一个api,并且我成功地得到了json的响应,但是我无法打印json响应的值。我是json新手,如果有人能帮助我,我会很高兴。我得到的回应是 [{“编号”:“3323-23232”,“更新地址”:“2018-04-09 11:15:53,“创建时间”:“2018-04-09 11:15:53”,“id”:2,“消息”:“亲爱的” dasdas!您的预订付款到期了。请及时付款 付款。“,“状态”:0}] 如何打印它的值 我获取json响应的代码是

我已经使用unirest调用了一个api,并且我成功地得到了json的响应,但是我无法打印json响应的值。我是json新手,如果有人能帮助我,我会很高兴。我得到的回应是

[{“编号”:“3323-23232”,“更新地址”:“2018-04-09 11:15:53,“创建时间”:“2018-04-09 11:15:53”,“id”:2,“消息”:“亲爱的” dasdas!您的预订付款到期了。请及时付款 付款。“,“状态”:0}]

如何打印它的值

我获取json响应的代码是

          //calling thread to take json
  // calling to json data url          
  HttpResponse<JsonNode> response = Unirest.get("............").
        header("accept",  "application/json"). asJson();

   System.out.println(response.getBody());

  try {
   JSONObject responeJson = new JSONObject(response);

                JSONArray jsonArray = responeJson.getJSONArray("results");

                for (int i=0;i<jsonArray.length();i++){
                    System.out.println("Number : "+jsonArray.getJSONObject(0).getString("number"));

                }

  }
  catch (Throwable e){
            e.printStackTrace();
        }
//调用线程获取json
//调用json数据url
HttpResponse response=Unirest.get(“………”)。
标题(“接受”、“应用程序/json”)。asJson();
System.out.println(response.getBody());
试一试{
JSONObject responeJson=新的JSONObject(响应);
JSONArray JSONArray=responeJson.getJSONArray(“结果”);
对于(int i=0;i尝试:

JSONArray jsonarray = new JSONArray(jsonStr);
    for (int i = 0; i < jsonarray.length(); i++) {
        JSONObject jsonobject = jsonarray.getJSONObject(i);
        String number = jsonobject.getString("number");
        String updated_at = jsonobject.getString("updated_at");
        String created_at = jsonobject.getString("created_at");
        String id = jsonobject.getString("id");
        String message = jsonobject.getString("message");
        String status = jsonobject.getString("status");
                }

JSONArray-JSONArray=新的JSONArray(jsonStr);
for(int i=0;i
您能提供负责的代码片段吗?谢谢您的回复。我已经添加了调用url以获取响应的代码如何JSONArray JSONArray=responeJson。getJSONArray(“结果”);可以工作吗?字符串“results”不是json数组。非常感谢您的回复,但我仍然收到一个错误“org.json.JSONException:JSONArray初始值应该是一个字符串、集合或数组。在org.json.JSONArray.(JSONArray.java:208)”您可以发布您的第一行,即json数组声明行JSONArray JSONArray=new JSONArray(response);Try:JSONArray JSONArray=new JSONArray(response.getBody().toString());让我们看看。