我有一个格式为的 JSON 数据
[{"product_id":"33","amount":"1"},{"product_id":"34","amount":"3"},{"product_id":"10","amount": "1"},{"用户名":"test"}]
现在我想在我的 PHP Web 系统中获取这些数据。我正在将这些数据从 android 应用程序发送到 PHP 服务器。我正在使用下面的代码将其发送到 Web 服务器。
public JSONObject sendAndGetJSONfromURL(String url,List<NameValuePair> params){
InputStream is = null;
String result = "";
JSONObject jArray = null;
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-type", "application/json");
httppost.setHeader("Accept", "application/json");
httppost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
.....
在发送之前,我打印
jArray.toString()并得到输出
[{"product_id":"33","amount":"1"},{"product_id":"34","amount":"3"},{"product_id":"10","amount":"1"},{"username":"test"}]
我想知道如何从 PHP 系统中获取这些值。谁能帮帮我吗?
在通过 HTTPRequest 发送之前,params 变量值的输出如下所示
[cartdata=[{"product_id":"33","amount":"1"},{"product_id":"34","amount":"3"},{"product_id":"10","amount":"1"},{"username":"UWUDAMITH"}]]