Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailem Codename One - JSON Parser

Zdravím,

dělám projekt do Codename One v Netbeans, cílem je načíst data ze serveru Rotten Tomatoes a vypsat informace např. o délce filmu, hodnocením, datu vydání, atd..

Zatím se mi podařilo načíst data ze serveru pomocí JSON Parseru, ale nedaří se mi je zapsat, např. chtěl bych vypsat celkový počet filmů (total)

Hodnotu jsem chtěl uložit do Labelu pomocí ".get" ale nedaří se, prosím o pomoc.

výpis z JSON:

{"total":25,"movies":[{"id":"12897","title":"The Matrix","year":1999,"mpaa_rating":"R","runtime":13 6,"critics_consensus":"An ingenious combination of Hong Kong action, ground-breaking Hollywood FX, and an imaginative vision.","release_dates":{"theater":"1999-03-31"," dvd":"1999-09-21"},"ratings":{"critics_rating":"Ce rtified Fresh","critics_score":87,"audience_rating":"Uprig ht","audience_score":85},"synopsis":"","posters":

kód aplikace:

/**
* Your application code goes here
*/

package userclasses;

import com.codename1.components.InfiniteProgress;
import com.codename1.io.ConnectionRequest;
import com.codename1.io.JSONParser;
import com.codename1.io.NetworkManager;
import generated.StateMachineBase;
import com.codename1.ui.*;
import com.codename1.ui.events.*;
import com.codename1.ui.util.Resources;
//import com.sun.org.apache.xalan.internal.xsltc.runtime.Ha shtable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Hashtable;

/**
*
* @author Your name here
*/
public class StateMachine extends StateMachineBase {
public StateMachine(String resFile) {
super(resFile);
// do not modify, write code in initVars and initialize class members there,
// the constructor might be invoked too late due to race conditions that might occur
}

/**
* this method should be used to initialize variables instead of
* the constructor/class scope to avoid race conditions
*/
protected void initVars(Resources res) {
}

@Override
protected void onMain_AskAction(final Component c, ActionEvent event) {

ConnectionRequest r = new ConnectionRequest() {
Hashtable h;

@Override
protected void postResponse() {
// findDest(c);
findDest(c).addComponent(new Label("" + h.get ("total")));

c.getComponentForm().revalidate();

}

@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
// java.util.Hashtable<String, Object> h = p.parse(new InputStreamReader(input));
Hashtable h = p.parse(new InputStreamReader(input));
System.out.println("" + h);

}

};
r.setUrl("http://api.rottentomatoes.com/api/public/v1.0/movi es.json?apikey=6w8syzj56nskryfy2jar7dk6&q=matrix");
r.setPost(false);
InfiniteProgress prog = new InfiniteProgress();
Dialog dlg = prog.showInifiniteBlocking();
r.setDisposeOnCompletion(dlg);
NetworkManager.getInstance().addToQueue(r);

// NetworkManager.getInstance().addToQueueAndWait(r);
// r.getResponseData();

Předmět Autor Datum
Nenašly se žádné odpovědi.

Zpět do poradny Odpovědět na původní otázku Nahoru