I want to get some values from a JSON using this url:http://api.bitcoincharts.com/v1/markets.json
. Im using quick-json
to parse it the problem is i don't know how to do it since JSON is very confusing to me in JAVA.
I want to get the values that you get here http://api.bitcoincharts.com/v1/markets.json and put them in Hashmap... so i can retrieve them by keys using quick-json for parsing ... can anyone help me tell me how should i proceed using the following code?
import com.json.parsers.JSONParser;
import com.json.parsers.JsonParserFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import sun.org.mozilla.javascript.internal.json.JsonParser;
public class Restfultest {
public static float [] lastprice = new float[5000];
public static float [] amounttraded = new float[5000];
public static String allvalue;
public static int value = 0;
public static String [] s = new String[4];
public static void main(String[] args) {
try {
URL url = new URL("http://api.bitcoincharts.com/v1/markets.json");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
/*
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));*/
JsonParserFactory factory=JsonParserFactory.getInstance();
JSONParser parser=factory.newJsonParser();
Map jsonData=parser.parse(conn.getInputStream()); /*Gives error because of conn.getInputStream*/
/*
parsing...
*/
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
the error i get in that line its because the object i put in parse is of type JSONParser how do i use JSON at Java at ALL? this is very confusing... cant find any good examples that show how to connect to an Web API and retrieve some values ...
Really would appreciate some help ... thanks ...