-4

这是我的 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"}
]

在此代码中,我需要获取该前景 ID。如何在数组 php 代码中获取该前景 ID?

4

2 回答 2

0

[]是一个数组,{}是一个 Javascript 对象。

如果您从 Ajax 调用中将其转换为变量,例如 jsonData,您的库应该解析该字符串,将其转换为 Javascript 数组和对象。检查您的库文档,您可能必须指定响应的格式('json')。

完成此操作后,您只需访问前景 ID.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 来迭代数组

于 2013-08-26T09:21:28.107 回答
0

首先你需要改变你的 json 字符串。

" "零。

使用以下代码获取'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>";
}
于 2013-08-26T09:44:03.357 回答