使用Java粘贴JSON数据 [英] Pasring JSON data using Java
本文介绍了使用Java粘贴JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,用于从字符串json数据获取与属性名称和值关联的代码.该代码在没有错误的情况下被执行,但是我得到的结果为null.
This is my code for getting the atribute name and value assosiated with it fromstring json data .The code is getting executed without errror but i am getting the result as null.
import java.io.*;
import java.net.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class A18 {
public static void main(String[] args) throws ParseException{
String[] out2;
String out,out1= null;
try{
URL a=new URL("URL");
HttpURLConnection b=(HttpURLConnection) a.openConnection();
b.setRequestMethod("GET");
b.setRequestProperty("Accept", "application/json");
BufferedReader c=new BufferedReader(new InputStreamReader(b.getInputStream()));
StringBuilder sb=new StringBuilder();
while((out=c.readLine())!=null)
{
sb.append(out);
out1=sb.toString();
}
c.close();
b.disconnect();
JSONObject obj = new JSONObject();
String id = obj.toJSONString("collection");
String error = obj.toJSONString("links");
}
catch (Exception e)
{
e.printStackTrace();
return;
}
}}
推荐答案
在所有以上导入代码中,您都有import org.json.JSONObject
,将其更改为import org.json.simple.JSONObject
应该会有所帮助.
In your imports code above all of this you're having import org.json.JSONObject
, changing that to import org.json.simple.JSONObject
should help.
很可能您还需要导入其他org.json.x
,您必须将其更改为org.json.simple.x
.
Most probably you'll have other imports of org.json.x
you'll have to change to org.json.simple.x
.
这篇关于使用Java粘贴JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文