我知道这个已经被问了很多次,所以mod请不要关闭它,因为没有过去的答案有效,我已经搜索过了!所以我正在使用HaveIBeenPwned API,它输出显然是JSON的东西:
[
{
"Title":"000webhost"
,"Name":"000webhost"
,"Domain":"000webhost.com"
,"BreachDate":"2015-03-01"
,"AddedDate":"2015-10-26T23:35:45Z"
,"PwnCount":12345678
,"Description":"In approximately March 2015, the free web hosting provider 000webhost suffered a major data breach that exposed over 13 million customer records. The data was sold and traded before 000webhost was alerted in October. The breach included names, email addresses and plain text passwords."
,"DataClasses":[
"Email addresses"
,"IP addresses"
,"Names"
,"Passwords"
]
,"IsVerified":true
,"IsSensitive":false
,"LogoType":"png"
}
]
如果我使用以下内容,那就是输出:
echo $output;
json_decode($output)
不起作用。使用foreach($output as $key)
不起作用,如果我使用它,则表示无效参数。我尝试了一个正常的for()
循环,但再次没有快乐。这个输出有什么问题?我如何获得其中的值?正如你应该能够告诉我正在使用PHP。
答案 0 :(得分:1)
使用json_decode($output, true);
第二个参数定义结果数据格式 - 对象(false,默认)或关联数组(true)。