普通网友 2017-07-25 06:08
浏览 45
已采纳

我如何获得数组结果的值?

I'm new and I work in php. I have a problem, I have this "array" result from php script (this array was extracted with php of a html page):

Array ( [0] => {"autostart": false,"controls": true,"flashplayer": "/jwplayer7/jwplayer.flash.swf","image": "I NEED THIS", ga: {}, "mute": false, "ph": 1, "preload": "none", "primary": "html", "repeat": false, "skin": { "name": "tube" }, "stagevideo": true, "stretching": "uniform", "visualplaylist": true, "width": "100%", "aspectratio": "16:9", "provider": 'http', "startparam": "start", tracks: [{"file":"I WANT THIS","kind":"thumbnails"}], "sources": [{"file":"I NEED THIS","label":"480p"},{"file":"I NEED THIS","label":"720p"},"I WANT THIS"] ,"logo": {"logoBar": "I NEED THIS", "target": "blank","link": ""},"displaydescription": false,"displaytitle": false , "abouttext": "RapTu Player", "aboutlink": "" } )

I only need the values from image:, sources:[{"file";}} but I can't get the values, nothing, I try with javascript:

var str = '<?php echo $jw; ?>';
var json = JSON.parse(str);
var parse = $.parseJSON(file);

$jw is the variable of the array, and I don't have any result, nothing is printed. Could you help me? (Sorry for my english).

Upgrade: I resolved it using:

object = [<?php echo $jw; ?>]
for(f=0;f<object.length;f++){
}

Thanks everybody!

  • 写回答

2条回答 默认 最新

  • douzangdang2225 2017-07-25 06:14
    关注

    if you want doing that. Then use

    var json = '<?php echo json_encode($jw); ?>';
    

    and in json variable you have json from array

    or if you only sources you can use

    var json = '<?php echo json_encode($jw[0]["sources"]); ?>';
    

    but only work with first element in array $jw

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 解决websocket跟c#客户端通信
  • ¥30 Python调用dll文件输出Nan重置dll状态
  • ¥15 浮动div的高度控制问题。
  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题
  • ¥15 pic16F877a单片机的外部触发中断程序仿真失效
  • ¥15 Matlab插值拟合差分微分规划图论
  • ¥15 keil5 target not created
  • ¥15 C/C++数据与算法请教