这是我的Json代码
[
{"ProspectID":"87f3278e-c9ee-4775-abc6-4813969d45a5",
"FirstName":"erter",
"LastName":"nurtertel",
"EmailAddress":"null",
"Company":"null",
"Phone":"null",
"Mobile":"456456456",
"Total":"690"},
{"ProspectID":"00969dcd-5c03-450e-832c-063e976285d5",
"FirstName":"rter",
"LastName":"erte",
"EmailAddress":"null",
"Company":"null",
"Phone":"56456456",
"Mobile":"null",
"Total":"690"}
]
在这段代码中我需要获取那个prospectID.how来获取数组php代码中的那个prospectID吗?
答案 0 :(得分:0)
[]
是一个数组,{}
是一个Javascript对象。
如果你从Ajax调用中将它变成一个变量,例如jsonData,你的库应该解析该字符串,将其转换为Javascript数组和对象。 检查您的库文档,您可能必须指定响应的格式('json')。
完成此操作后,您只需访问prospectID.how,如下所示:
var jsonData = your parsed string;
alert('ProspectID of first item is: ' + jsonData[0].ProspectID);
alert('ProspectID of second item is: ' + jsonData[0].ProspectID);
显然,您也可以使用for..loop
迭代数组答案 1 :(得分:0)
首先你需要改变你的json字符串。
将" "
置于null。
使用以下代码获取'ProspectID'
$json = '[{"ProspectID":"87f3278e-c9ee-4775-abc6-4813969d45a5","FirstName":"erter","LastName":"nurtertel","EmailAddress":"null","Company":"null","Phone":"null","Mobile":"456456456","Total":"690"},{"ProspectID":"00969dcd-5c03-450e-832c-063e976285d5","FirstName":"rter","LastName":"erte","EmailAddress":"null","Company":"null","Phone":"56456456","Mobile":"null","Total":"690"}]';
$data = json_decode($json);
for($i=0; $i<count($data); $i++ ){
$ProspectID = $data[$i]->{'ProspectID'};
echo $ProspectID."<br>";
}