简体   繁体   English

创建 JSONObject 实例时出现问题

[英]A problem when creating an instance of JSONObject

I am new to java, and I have seen a lot of people using JSONObject like this:我是 java 的新手,我见过很多人像这样使用 JSONObject:

 String content ="....";
 JSONObject Object1 = new JSONObject(content);

But when I do that, there appears that: enter image description here但是当我这样做时,似乎:在此处输入图像描述

What's wrong, please help me.(I have "import net.sf.json.JSONObject")怎么了,请帮帮我。(我有“import net.sf.json.JSONObject”)

The JSONObject you provided is from the popular org.json library which contains a constructor like your example.您提供的JSONObject来自流行的org.json库,其中包含与您的示例类似的构造函数

So simply switch to this lib.所以只需切换到这个库。

What it seems, is that you are importing the wrong library.看起来,您正在导入错误的库。 The library that you are using doesn't have a constructor that receives a string parameter only a boolean:您正在使用的库没有仅接收字符串参数的构造函数 boolean:

http://json-lib.sourceforge.net/apidocs/jdk15/net/sf/json/JSONObject.html#JSONObject(boolean) http://json-lib.sourceforge.net/apidocs/jdk15/net/sf/json/JSONObject.html#JSONObject(boolean)

The library that you are trying to use when you are initializing a new instance of JSONObject is from Google:您在初始化JSONObject的新实例时尝试使用的库来自 Google:

https://developer.android.com/reference/org/json/JSONObject#JSONObject(java.lang.String) https://developer.android.com/reference/org/json/JSONObject#JSONObject(java.lang.String)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM