JohnDoe4136 JohnDoe4136 - 3 months ago 10
Java Question

Convert Java String to Json

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;
}
}

Answer

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