1

I have a list of String which I wish to convert to Json. I am using org\json\me in order to do so. However, I don't know how to continue from here. A little help will be appreciated. Thanks.

This is my code:

public class PhoneData implements JSONAble {

    private Display display;   
    private Form mainScr;

    public PhoneData() {   

        mainScr = new Form("Phone Data");
        String imei = IDENInfo.imeiToString(IDENInfo.getIMEI());

        String imsi = new String();
        try{
            imsi=GPRSInfo.imeiToString(SIMCardInfo.getIMSI(), false );           
        }catch(SIMCardException ioe){}   
        String majorOS = DeviceInfo.getPlatformVersion(); 
        int content = CodeModuleManager.getModuleHandle("net_rim_bb_phone_api"); 
        String version = CodeModuleManager.getModuleVersion(content); //DeviceInfo.getSoftwareVersion();  
        String modelnumber = DeviceInfo.getDeviceName(); //get modelnumber


        String [] phoneData = new String[] { modelnumber = "Model Number", majorOS = "majorOS", version = "softwareversion"
            ,imei = "imei", imsi = "imsi"};  // an Array

    }


    protected void startApp() throws MIDletStateChangeException {
        // TODO Auto-generated method stub

        display.setCurrent(mainScr);
        PhoneData user = new PhoneData(); 
    }


    public void fromJSON(String jsonString) {
        // TODO Auto-generated method stub

    }

    public String toJSON() {
        // TODO Auto-generated method stub
        return null;
    }
}
1
  • why are your redifining your data inside you array ? are you trying to make a map ? Nov 8, 2010 at 9:01

3 Answers 3

2

You'll have to put your data inside a Vector, then use the new JSONArray(yourvector) to make a JSONArray.

1
  • I have done Vector vector = new Vector(5, 3); vector.addElement(imei); vector.addElement(imsi); vector.addElement(majorOS); vector.addElement(modelnumber); vector.addElement(version); Nov 11, 2010 at 7:23
0

Unless you specifically want to use org.json's barebones package, maybe have a look at this question.

-1

You could use the Jettison driver with XStream to serialize / deserialize string <-> json : http://x-stream.github.io/json-tutorial.html

I had used this sometime back - there are some caveats on how the json schema should be for the parser to parse perfectly well.

2
  • Will this be very different from using org\json\me? Nov 8, 2010 at 9:39
  • Sorry. I've not used org.json.me.*. Nov 8, 2010 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.