我正在尝试将此 json 发送到 Web 服务器:
[{"codemenu":"1","name":"Fried Rice"},
{"codemenu":"2","name":"Hongkong Fried Rice"},
{"codemenu":"3","name":"Special fried Rice"}]
这是代码,但它不起作用:
HttpPost httppost = new HttpPost("http://10.0.2.2/pnir_restoran/test.php");
JSONObject json = new JSONObject();
try {
// JSON data:
json.put("codemenu", "1");
json.put("name", "friedrice");
json.put("codemenu", "2");
json.put("name", "Hongkong friedrice");
json.put("codemenu", "3");
json.put("name", "Special friedrice");
JSONArray postjson=new JSONArray();
postjson.put(json); //i cant use postjson.add(json);
// Post the data:
httppost.setHeader("json",json.toString());
httppost.getParams().setParameter("jsonpost",postjson);
// Execute HTTP Post Request
System.out.print(json);
HttpResponse response = httpclient.execute(httppost);
我应该怎么办?请帮我。