java转android理由,Android java http Xml转换为Json的原因:java.lang.NoSuchMethodError:没有直接方法< init>(Ljava...

I have to convert an Xml file at a very heavy http into a Json file.

I tried to use: implementation 'org.json: json: 20180813'

But it gives me the following error:

Caused by: java.lang.NoSuchMethodError: No direct method (Ljava / me / Reader;) V in class Lorg / json / JSONTokener; or its super classes (declaration of 'org.json.JSONTokener' appears in /system/framework/core-libart.jar)

at org.json.XMLTokener. (XMLTokener.java:57)

at org.json.XML.toJSONObject (XML.java:516)

at org.json.XML.toJSONObject (XML.java:548)

at org.json.XML.toJSONObject (XML.java:472)

If I go to the build.gradle file, on the lib in question it tells me:

json defines classes that conflict with classes now provided by Android. Solutions includes finding newer versions or alternative libraries that do not have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.

So I tried to use: Link

But it does not work.

Can you tell me where I'm wrong?

Or a solution.

Code http:

private class Html extends AsyncTask {

private String url = "https://pastebin.com/raw/ExP2Mm2k";

private JSONArray listCh = new JSONArray();

@Override

protected void onPreExecute() {

super.onPreExecute();

}

@Override

protected Void doInBackground(Void... params) {

try {

Log.v("Class:" + TAG, "doInBackground:" + url);

String jsonString = Jsoup.connect(url).execute().body();

//Log.v("Class:" + TAG, "" + jsonString);

/* try {

JSONObject xmlJSONObj = XML.toJSONObject(jsonString);

String jsonPrettyPrintString = xmlJSONObj.toString(4);

System.out.println(jsonPrettyPrintString);

} catch (JSONException je) {

System.out.println(je.toString());

}*/

try {

JSONObject json = new JSONObject(jsonString);

JSONArray list = json.getJSONObject("list").getJSONArray("item");

//Log.v("Class:" + TAG, String.valueOf(listCh));

} catch (JSONException e) {

e.printStackTrace();

}

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

@Override

protected void onPostExecute(Void result) {

populateListItem(listCh);

}

}

解决方案

I had to bring in org.json lib as source files to change the package name to get it to stop conflicting with the org.json packaged with Android.

If you don't want to hand edit the package names, you might be able to use something like jarjar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值