Blackberry json parser -


i want create simple json parser blackberry test. found this example, , implement code follows

import java.io.bytearrayoutputstream; import java.io.inputstream; import java.util.vector; import javax.microedition.io.connector; import javax.microedition.io.httpconnection; import org.json.me.jsonarray; import org.json.me.jsonobject; import net.rim.device.api.ui.component.dialog; import net.rim.device.api.ui.container.mainscreen;   public final class myscreen extends mainscreen { httpconnection conn = null; inputstream in = null; string _response = null; vector _adbeanvector=null; int code; public myscreen() {                  settitle("mytitle");     try      {     stringbuffer url=new stringbuffer().append("http://codeincloud.tk/json_android_example.php");     conn = (httpconnection) connector.open(url.tostring(), connector.read);     conn.setrequestmethod(httpconnection.get);      code = conn.getresponsecode();     if (code == httpconnection.http_ok) {     in = conn.openinputstream();     bytearrayoutputstream out = new bytearrayoutputstream();     byte[] buffer = new byte[in.available()];     int len = 0;     while (-1 != (len = in.read(buffer))) {     out.write(buffer);      }     out.flush();     _response = new string(out.tobytearray());     jsonobject resobject=new jsonobject(_response);     string _key =resobject.getstring("insert json key");      _adbeanvector = new vector();     jsonarray newsarray = resobject.getjsonarray("insert json array key");     if(newsarray.length() > 0)     {     (int i=0 ;i <  newsarray.length() ; i++)      {     vector _adelementsvector=new vector();     jsonobject newsobj = newsarray.getjsonobject(i);     _adelementsvector.addelement(newsobj.getstring("message"));     //_adelementsvector.addelement(newsobj.getstring("insert json array element key2"));     _adbeanvector.addelement(_adelementsvector);     }     }     if (out != null){     out.close();     }     if (in != null){     in.close();     }     if (conn != null){     conn.close();     }     }      } catch (exception e)      {     dialog.alert(e.getmessage());     } } } 

but cannot modify purpose. can 1 me modify code sample access this json. i'm new subject area.

thank in advance.

try -

 jsonobject resobject=new jsonobject(_response);  string _name=resobject.getstring("name"); //this result froyo  string _version=resobject.getstring("version");  //this result android 2.2     dialo.alert("name : "+_name+" , version : "+_version); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -