public class DemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
JSONArray jsonarray=new JSONArray();
jsonarray.put("Info");
JSONObject j1=new JSONObject();
try {
j1.put("NAME", "NAKUL");
j1.put("ADDRESS", "NASHIK");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
jsonarray.put(j1);
Log.d("Test",jsonarray.toString());
}
}
它给了我输出
12-10 14:14:59.639: D/Test(862): ["Info",{"ADDRESS":"NASHIK","NAME":"NAKUL"}]
但我需要输出
["Info":{"ADDRESS":"NASHIK","NAME":"NAKUL"}]
这意味着我需要“:”而不是“,”