2014-04-03 37 views
0

我有jquery.tokenInput的问题。JSON解析器与jquery.TokenInput(格式)

这是我的tokenInput代码:

$(".search-betrocket").tokenInput("http://www.websitehere.com/web/search", { 

    searchDelay: 2000, 
    minChars: 3, 
    tokenLimit: 5, 
    hintText: "Buscador inteligente...", 
    noResultsText: "Sin resultados", 
    searchingText: "Buscando...", 
    theme: "facebook", 
    queryParam: "txt", 
    propertyToSearch: "NickName", 

    resultsFormatter: function(item){ return "<li>" + "<img src='" + Users.Avatar + "' title='" + item.first_name + " " + item.last_name + "' height='25px' width='25px' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.first_name + " " + item.last_name + "</div><div class='email'>" + item.email + "</div></div></li>" }, 

    tokenFormatter: function(item) { return "<li><p>" + item.first_name + " <b style='color: red'>" + item.last_name + "</b></p></li>" } 
}); 

问题是去解析... jQuery的了解不多,以了解JSON解析器返回的对象。

这是我的代码JSON结果_ GET请求

{ 
    Users: [ 
     { 
      Id: 264, 
      NickName: "SirBet", 
      Avatar: "19b452bf3fe83e17de82b67e518361d2", 
      Ranking: 3233, 
      FirstName: "Sir", 
      LastName: "Bettor", 
      Gender: "H", 
      Location: "Valencia", 
      Description: "Acepto todo tipo de retos :)", 
      CountryId: 1, 
      Country: "España", 
      CountryISO: "ES", 
      PrivacyUpdated: 0 
     } 
    ] 
} 

什么也不是如何导航JSON对象才能正常工作。 即通过输入$ val ['Users'] ['0'] ['Nickname'] format但jquery/json。

有人帮我吗?

+0

你什么错误?另外,是从您的网站的JSON输出的直接副本?如果是这样,它是无效的。 JSON要求使用双引号括起键名:''' – JAAulde

回答

0

如果乌拉圭回合JSON是...

[{Id:1, NickName:xxxx, Avatar: "19b452bf3fe83e17de82b67e518361d2", Ranking: 3233}] 

然后..

$.each(data, function(a, b) { 

    alert (b.Id); 
    alert (b.NickName); 
    alert (b.Avatar); 
    alert (b.Ranking); 

}); 
+0

Mmmmmm对不起JAAulde这不是我的JSON这是de问题,我不知道解析器json是jQuery格式。 编号:264, 绰号: “SirBet”, 阿凡达: “19b452bf3fe83e17de82b67e518361d2”, 排名:3233, 姓: “先生”, 名字: “打赌”, 性别: “H”, 位置:“瓦伦西亚“, 描述:”Acepto todo tipo de retos :)“, 国家号码:1, 国家:”España“, CountryisO:“ES”, PrivacyUpdated:0 } ] } – cbeneyto