As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center提供指导。
已关闭8年。
因此,我得到了该数组(请参见下文),方法是获取API URL的file_contents,然后对结果进行json_decode($ url,true)以获得数组。
因此,该数组位于名为$ strain_data的变量中,当我尝试访问该数组时,请说类似以下内容:echo $ strain_data ['name'];我收到这样的错误:
我唯一能做的就是计算总共有多少项($ strain_total = count($ strain_data);),表示有545个。
我真的不明白。如果您能帮助解释这一点,我将不胜感激。
谢谢!
已关闭8年。
因此,我得到了该数组(请参见下文),方法是获取API URL的file_contents,然后对结果进行json_decode($ url,true)以获得数组。
Array ( [0] =>
Array (
[Id] => 1104
[Key] => 100-og
[Name] => $100 OG
[Category] => Hybrid
[Symbol] => 100
[Abstract] =>
[Url] => http://www.leafly.com/hybrid/100-og
[DetailUrl] => http://www.leafly.com/api/details/100-og
[RateUrl] => http://www.leafly.com/me/create/100-og
[Rating] => 8.2
[TopEffect] => Euphoric
[TopMedical] => Stress
[TopActivity] => Relax at home )
)
因此,该数组位于名为$ strain_data的变量中,当我尝试访问该数组时,请说类似以下内容:echo $ strain_data ['name'];我收到这样的错误:
我唯一能做的就是计算总共有多少项($ strain_total = count($ strain_data);),表示有545个。
我真的不明白。如果您能帮助解释这一点,我将不胜感激。
谢谢!
最佳答案
区分大小写会严重打击您。 -它是Name
而不是name
。除此之外,由于您拥有数组数组,因此您忘记了[0]
。
试试$strain_data[0]['Name']
关于php - PHP/ARRAYS/API/JSON-我不明白为什么我没有得到任何结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10864395/