欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-03-11 17:07:18
...
这两天搞微信企业号接口,获取了一段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)