我需要处理以json格式提供给我的一些数据,我需要从中提取一些数据并将其放入PHP中的变量中。
尽力而为,我似乎最终会遇到诸如以下错误:
Use of undefined constant collectionViewUrl - assumed 'collectionViewUrl'
目前,我唯一的真实代码是这样的:
$string = file_get_contents("https://itunes.apple.com/search?term=rihanna+diamonds&country=gb&media=music&entity=musicTrack&attribute=musicTrackTerm&limit=1");
$json_result = json_decode($string, true);
我不需要任何类型的数组,只需要将collectionViewUrl的值放入变量中即可。
在这里,如何将collectionViewUrl字符串转换为变量
$string = file_get_contents("https://itunes.apple.com/search?term=rihanna+diamonds&country=gb&media=music&entity=musicTrack&attribute=musicTrackTerm&limit=1");
$json_result = json_decode($string, true);
$collectionViewUrl = $json_result['results'][0]['collectionViewUrl'];
这是一个键盘,您可以在其中尝试使用代码http://codepad.org/6Zogs3si
解释 :
将的第2个参数json_decode
设置为true时,该函数将返回一个与JSON结构非常接近的关联数组。
从那里开始,所有要做的就是将JSON路径放回关联的php数组中,以访问所需的值!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句