当前位置:Gxlcms > PHP教程 > PHP获取JSON生成select下拉选框有关问题

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

时间:2021-07-01 10:21:17 帮助过:10人阅读

PHP获取JSON生成select下拉选框问题
这两天搞微信企业号接口,获取了一段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\":[]}]}"


------解决思路----------------------
不劳而获是大忌,给你写个示例,结合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)

人气教程排行