json_decode在PHP中不起作用

I have this json_encode data:

{\"MOT:D44-538JK\":{\"productid\":\"MOT:D44-538JK\",\"qty\":\"1\"}}

When I use json_decode on the above string it is not working. Any one can assist what parameters need to pass to work.

Your data is encoded already.

php > var_dump(json_decode("{\"MOT:D44-538JK\":{\"productid\":\"MOT:D44-538JK\",\"qty\":\"1\"}}", true));
array(1) {
  'MOT:D44-538JK' =>
  array(2) {
    'productid' =>
    string(13) "MOT:D44-538JK"
    'qty' =>
    string(1) "1"
  }
}

Remove "\" from jsonstring

<?php 
    $c = '{"MOT:D44-538JK":{"productid":"MOT:D44-538JK","qty":"1"}}';
    $r = json_decode($c);
    echo "<pre>";
    print_r($r);

?>

I think your JSON has padding. Please remove the padding then process further:

$json=preg_replace('/.+?({.+}).+/','$1',$json); 

// now, process the JSON string 

$result = json_decode($body); 

The JSON does not validate. Test it here: http://jsonlint.com This does, so the slashes need to go.

{
    "MOT:D44-538JK": {
        "productid": "MOT: D44-538JK",
        "qty": "1"
    }
}

try this

$Json = '{"MOT:D44-538JK":{"productid":"MOT:D44-538JK","qty":"1"}}';
$jsonDec = json_decode($Json, true);
var_dump($jsonDec);

OUTPUT Like this:

array (size=1)
'MOT:D44-538JK' => 
array (size=2)
  'productid' => string 'MOT:D44-538JK' (length=13)
  'qty' => string '1' (length=1)