Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提取json对象并填充用户标签_Json - Fatal编程技术网

提取json对象并填充用户标签

提取json对象并填充用户标签,json,Json,这就是控制器以json格式返回数据的方式 我想以以下格式存储它: [{"id":1,"name":"ABC"},{"id":2,"name":"XYZ"}] 下面是我使用过但不起作用的代码 var json = { "users": [ { "id": "1", "name": "ABC" }, { "id": "2", "name": "XYZ" }, ] } 感谢您的帮助。提前感谢。$。getJson是异

这就是控制器以json格式返回数据的方式

我想以以下格式存储它:

[{"id":1,"name":"ABC"},{"id":2,"name":"XYZ"}]
下面是我使用过但不起作用的代码

var json = {
"users": [
             { "id": "1", "name": "ABC" },
             { "id": "2", "name": "XYZ" },
         ]
       }

感谢您的帮助。提前感谢。

$。getJson是异步的,因此您需要使用成功回调来获取响应并执行操作。试试这个

  var json = 
  {
     "users": $.getJSON("@Url.Action("SearchCMSAdmins")")
  }              

 $("#DistributorCMSAdmin").tokenInput("@Url.Action("SearchWithName")", {
    theme: "facebook",                
    preventDuplicates: true,
    prePopulate:json.users
 });
$.getJSON("@Url.Action("SearchCMSAdmins")",function(data){
    var json= {"users":data};
    $("#DistributorCMSAdmin").tokenInput("@Url.Action("SearchWithName")", {
       theme: "facebook",                
       preventDuplicates: true,
       prePopulate:json.users
    });
});