首頁  >  文章  >  後端開發  >  PHP获取JSON生成select下拉选框问题

PHP获取JSON生成select下拉选框问题

WBOY
WBOY原創
2016-06-23 13:39:481276瀏覽

    这两天搞微信企业号接口,获取了一段JSON,想在PHP里通过userlist中的usrid和name内容生成相关的select下拉选框,应该怎样写好,好似只能用AJAX来搞吧?

"{\"errcode\":0,\"errmsg\":\"ok\",\"userlist\":[{\"userid\":\"ersuo\",\"name\":\"\u6881\u51ef\u6b23\",\"department\":[]},{\"userid\":\"sabrina\",\"name\":\"\u8d75\u5b9d\u83b9\",\"department\":[]},{\"userid\":\"kelly\",\"name\":\"\u9648\u70ab\u534e\",\"department\":[]},{\"userid\":\"eva\",\"name\":\"eva\",\"department\":[]},{\"userid\":\"zhongzhong\",\"name\":\"\u949f\u548f\u6bb7\",\"department\":[]}]}"


回复讨论(解决方案)

就用ajax实现


求代码

不劳而获是大忌,给你写个示例,结合JQ

var a=JSON.parse("{\"errcode\":0,\"errmsg\":\"ok\",\"userlist\":[{\"userid\":\"ersuo\",\"name\":\"\u6881\u51ef\u6b23\",\"department\":[]},{\"userid\":\"sabrina\",\"name\":\"\u8d75\u5b9d\u83b9\",\"department\":[]},{\"userid\":\"kelly\",\"name\":\"\u9648\u70ab\u534e\",\"department\":[]},{\"userid\":\"eva\",\"name\":\"eva\",\"department\":[]},{\"userid\":\"zhongzhong\",\"name\":\"\u949f\u548f\u6bb7\",\"department\":[]}]}"); var select=""; $("body").append(select)

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn