普通网友 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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度