无法导入org.json.simple.JSONObject获取错误说“org.jason无法解析”

时间:2014-10-06 21:09:25

标签: java

我正在尝试编写一个读取Web服务的程序,并使用JSONObject对象对其进行短语处理。我正在使用eclipse

当我尝试导入org.json.simple.JSONObject库时; 我收到一条错误消息" org.jason无法解决"

代码列表

import java.net.URL;

import org.json.simple.JSONObject;

//错误消息"导入" org.json无法解析"

import java.io.*;
import javax.net.ssl.HttpsURLConnection; // This is where I get the error message

public class cStart {

    cGraphData ReadData;

     public static void main (String[] args) {

               System.out.println("Welcome to the world of Java Programming.");
               String reply="";
               cGraphData ReadData= new cGraphData();
              try {
               String httpsURL = "https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC";
               URL myurl = new URL(httpsURL);
               HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
               InputStream ins = con.getInputStream();
               InputStreamReader isr = new InputStreamReader(ins);
               BufferedReader in = new BufferedReader(isr);

               String inputLine;


               while ((inputLine = in.readLine()) != null)
               {
                   reply+=inputLine;
               }
              } catch (Exception e)
              {
                  System.out.println("Exception in getting data from server");
              }
              System.out.println(reply);
              JSONObject t;


}

}

2 个答案:

答案 0 :(得分:0)

只需将gradle或maven依赖项添加到项目中即可 为gradle:

compile group: 'org.json', name: 'json', version: '20180130'

for maven

<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20180130</version>
</dependency>

答案 1 :(得分:0)

您需要将以下依赖项添加到您的 pom.xml。 它将解析 for

import org.json.simple.JSONObject;