简体   繁体   中英

Parsing JSON from url in Java

(Prefacing this by saying that I am extremely new to JSON, aside from the last several hours I have spent trying to figure this out)

I am working on a personal android app that will search a URL that includes JSON data. For example: http://magictcgprices.appspot.com/api/images/imageurl.json?cardname=Pillar%20of%20Flame&cardset=fnmp

Provides the link to the card picture url.

Basically, it is a tool for Magic the Gathering so that I can search a card name and either have the picture shown to me, or bring the prices up with this URL:

http://magictcgprices.appspot.com/api/tcgplayer/price.json?cardname=Tarmogoyf&cardset=Modern%20Masters ----> Returns: ["$97.25", "$115.20", "$149.98"]

However, these JSON arrays do not have field names. I am stuck on how I will go about retrieving the JSON results from the webpage and relaying them back to java so I can manipulate them again. I have messed around with Jackson JSON libraries with no luck.

Try this..

JSONArray new_array = new JSONArray(response);
for(int i = 0; i < new_array.length; i++){
     System.out.println("Values : "+new_array.getString(i));
}

This should help:

JSONArray yourData = new JSONArray(response);
int len = yourData.length();
String data;
for (int i = 0; i < len; i++) {
    data = new String(yourData.get(i));
    System.out.println(data);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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