首页 >后端开发 >php教程 >PHP获取JSON生成select下拉选框问题

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

WBOY
WBOY原创
2016-06-23 13:39:481282浏览

    这两天搞微信企业号接口,获取了一段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