[英]Convert Java String to Json
I have a list of String which I wish to convert to Json. 我有一个String列表,希望将其转换为Json。 I am using org\\json\\me in order to do so.
我正在使用org \\ json \\ me来这样做。 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;
}
}
您必须将数据放入Vector
,然后使用new JSONArray(yourvector)
制作JSONArray
。
除非您特别想使用org.json的准系统软件包,否则请看一下这个问题 。
You could use the Jettison driver with XStream to serialize / deserialize string <-> json : http://x-stream.github.io/json-tutorial.html 您可以将Jettison驱动程序与XStream一起使用以对字符串<-> 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. 我曾经有一段时间使用过-关于解析器如何完美地解析json模式的一些警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.