-3
我的字符串數組每次通過循環將字符串數組轉換成JSON
apple
orange
我想我的字符串數組輸出轉換成JSON格式/ jsonarray迭代時間如下輸出。我試過,但它給輸出
{"fruits",apple}
{"fruits",orange}
我希望我的輸出
{"fruits": [
{
"1": "apple"
}
{
"2": "orange"
}
我嘗試下面的代碼
String[] strArray = new String[] {newString};
JSONObject json=new JSONObject();
//json.put("fruits", newString);
//System.out.println(json);
for(int i=0;i<strArray.length;i++)
{
System.out.print(strArray[i]+"\t");
json.put("",strArray[i]);
}