1

我在Android中有这个结构:

HttpPost post = new HttpPost(url);

        mjson.put("receiveOrderId", receiveOrderId);
        mjson.put("packageId", packageId);
        mjson.put("partNumber", partNumber);
        mjson.put("qty", qty);
        mjson.put("serial", serial);
        mjson.put("locationId", locationId);

        json.put("version", "6");
        json.put("token", token);
        json.put("data", mjson);

        post.setHeader("json", json.toString());
        StringEntity se = new StringEntity(json.toString());
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
                "application/json"));
        post.setEntity(se);
        response = client.execute(post);

而且我需要在php中解码,如何访问“partNumber”或“qty”的值?

尝试这种方式,但它不起作用:

$data = file_get_contents('php://input');
$json = json_decode($data);
$version = $json->{'version'};
$token = $json->{'token'};
$receiveOrderId = $json->{'receiveOrderId'};
$packageId = $json->{'packageId'};
$partNumber = $json->{'partNumber'};
$qty = $json->{'qty'};
$serial = $json->{'serial'};
$locationId = $json->{'locationId'};

*抱歉我的英语不好,我来自墨西哥。

4

1 回答 1

0

你能打印你的 $json 吗?

var_dump($json);

它必须看起来像:

'{"qty": 123, "version": "xxxxx"}';

确保索引名称(数量、版本、...)用双引号括起来,而不是单引号

于 2012-11-16T00:32:18.850 回答