将json代码转换为php数组

时间:2013-08-23 12:00:42

标签: php json api

这是我的代码iv需要转换PHP代码

{  "Parameter": {  "LookupName": "EmailAddress",
            "LookupValue": "asdasd@fgdfg.dfg"
        },
        "Columns": {  "Include_CSV": "ProspectID",
            "FirstName": "",
            "LastName": "",
            "EmailAddress": ""
        },
        "Sorting": {   "ColumnName": "FirstName",
            "Direction": "1"
        },
        "Paging": { "Offset": 0,
            "RowCount": 200
        }
    }

将详细信息发送到api。

3 个答案:

答案 0 :(得分:1)

试试这个,

<?php
    $json='{"Parameter": {  "LookupName": "EmailAddress",
            "LookupValue": "asdasd@fgdfg.dfg"
        },
        "Columns": {  "Include_CSV": "ProspectID",
            "FirstName": "",
            "LastName": "",
            "EmailAddress": ""
        },
        "Sorting": {   "ColumnName": "FirstName",
            "Direction": "1"
        },
        "Paging": { "Offset": 0,
            "RowCount": 200
        }
    }';
    $array = json_decode($json,true);
?>

阅读json-decode

答案 1 :(得分:1)

你需要这样的东西:

$json = '{  "Parameter": {  "LookupName": "EmailAddress",
            "LookupValue": "asdasd@fgdfg.dfg"
        },
        "Columns": {  "Include_CSV": "ProspectID",
            "FirstName": "",
            "LastName": "",
            "EmailAddress": ""
        },
        "Sorting": {   "ColumnName": "FirstName",
            "Direction": "1"
        },
        "Paging": { "Offset": 0,
            "RowCount": 200
        }
    }';

$array = json_decode($json, true);

var_dump($array);

输出

array (size=4)
  'Parameter' => 
    array (size=2)
      'LookupName' => string 'EmailAddress' (length=12)
      'LookupValue' => string 'asdasd@fgdfg.dfg' (length=16)
  'Columns' => 
    array (size=4)
      'Include_CSV' => string 'ProspectID' (length=10)
      'FirstName' => string '' (length=0)
      'LastName' => string '' (length=0)
      'EmailAddress' => string '' (length=0)
  'Sorting' => 
    array (size=2)
      'ColumnName' => string 'FirstName' (length=9)
      'Direction' => string '1' (length=1)
  'Paging' => 
    array (size=2)
      'Offset' => int 0
      'RowCount' => int 200

访问它

echo $array['Parameter']['LookupValue']; // Returns asdasd@fgdfg.dfg

答案 2 :(得分:0)

$array = json_decode($_POST['jsonvalue']);