JSON BEGIN_OBJECT error

Im experimenting with JSON and im trying to pull specific information...

import com.google.gson.Gson;

import com.google.gson.GsonBuilder;

import com.google.gson.JsonObject;

import com.google.gson.JsonParser;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.URL;

public class Json {

public static String toPrettyFormat(String jsonString)

{

JsonParser parser = new JsonParser();

JsonObject json = parser.parse(jsonString).getAsJsonObject();

Gson gson = new GsonBuilder().setPrettyPrinting().create();

String prettyJson = gson.toJson(json);

return prettyJson;

}

public static void main(String[] args) {

try {

URL url = new URL("https://api.coindesk.com/v1/bpi/currentprice/CAD.json");

System.setProperty("http.agent", "Chrome");

BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));

String str = "";

String msg = "";

while (null != (str = br.readLine())) {

msg = msg + str;

System.out.println("Test String 1 : "+toPrettyFormat(str));

}

System.out.println("Test String 2 : "+msg);

Gson gson = new Gson();

System.out.println("Test String 3 : "+str);

JClass jClass =...

Read More »

By: StackOverFlow - Monday, 16 April

Related Posts