0

次のjsonがJavaクラスから戻ってきました。これをJSで動作させることができます。ただし、phpでjsonデコードを使用すると、正しく解析するために正規表現を使用する必要があると確信しているため、明らかに機能しなくなります。何か案は?

{"return":"{\"response\": {\n \"header\": {\"status\": \"SUCCESS\"},\n \"table\":   {\"rows\": {\"row\": {\"category\": [ {\n \"id\": 1,\n \"name\": \"myApp\",\n \"fa\": [\n {\n \"id\": \"370\",\n \"FieldsAllowed\": \"true\",\n \"systemType\": \"CRM GT\",\n \"cachable\": \"false\",\n \"description\": \"Display Activities\",\n \"faId\": \"100000044\",\n  }]}}}\n}}"}
4

2 に答える 2

0

You can get the data either as an associative array or an object,

$jsonString = '{"return":"{\"response\": {\n \"header\": {\"status\": \"SUCCESS\"},\n \"table\":   {\"rows\": {\"row\": {\"category\": [ {\n \"id\": 1,\n \"name\": \"myApp\",\n \"fa\": [\n {\n \"id\": \"370\",\n \"FieldsAllowed\": \"true\",\n \"systemType\": \"CRM GT\",\n \"cachable\": \"false\",\n \"description\": \"Display Activities\",\n \"faId\": \"100000044\",\n  }]}}}\n}}"}';

1) Get the response as an associative array,

$decodedResultsAsArray = json_decode($jsonString,true);
$data = $decodedResultsAsArray['return'];
print_r($data);

2) Get the response as an object,

$decodedResultsAsObject = json_decode($jsonString);
$data = $decodedResultsAsObject->return;
print_r($data);

There are several other options with the json_decode function if you want to look at, http://php.net/json_decode

于 2013-12-23T00:16:23.997 に答える
0

2 回適用json_decode()して、含まれている配列 (「応答」) を取得します。

 // This gets you the inner string
 $json = json_decode($input);

 // This unfolds the contained structure
 $data = json_decode($data->return);

データが 2 回マーシャリングされたすべての場合と同じように。

于 2012-08-08T20:38:49.447 に答える