在这个插件中,每件事情都很好,这里的json就是这种格式。我对json很新,所以无法理解代码。
[
{id: 7, name: "Ruby"},
{id: 11, name: "Python"},
{id: 13, name: "JavaScript"},
{id: 17, name: "ActionScript"},
{id: 19, name: "Scheme"},
{id: 23, name: "Lisp"},
{id: 29, name: "C#"},
{id: 31, name: "Fortran"},
{id: 37, name: "Visual Basic"},
{id: 41, name: "C"},
{id: 43, name: "C++"},
{id: 47, name: "Java"}
]
但我的json是这样的。
{
"data": [
{id: 7, name: "Ruby"},
{id: 11, name: "Python"},
{id: 13, name: "JavaScript"},
{id: 17, name: "ActionScript"},
{id: 19, name: "Scheme"},
{id: 23, name: "Lisp"},
{id: 29, name: "C#"},
{id: 31, name: "Fortran"},
{id: 37, name: "Visual Basic"},
{id: 41, name: "C"},
{id: 43, name: "C++"},
{id: 47, name: "Java"}
],
"paging": {
"next": "https://graph.facebook.com/100000454970389/friends?access_token=AAAAAAITEghMBAPkZAGQhUiXWSeaewhYZBsZBXIs37swq4Th90HHIwYfKgm12M9u20UR9iqpeTtXv477ZAvx5nD0NsbSMJWlpTCNSrvxZCTVHg6upTAZBmV&limit=5000&offset=5000&__after_id=100004141210773"
}
}
这是我们正在解析json的javascript。
https://github.com/loopj/jquery-tokeninput/blob/master/src/jquery.tokeninput.js
提前感谢。
答案 0 :(得分:0)
我有解决方案
<script type="text/javascript">
$(document).ready(function() {
var url = 'https://graph.facebook.com/me/friends?access_token=<?php echo $access_token ?>';
$.getJSON(url,function(json){
beer = json.data;
console.log(beer);
var myJSONText = JSON.stringify(beer);
$("#demo-input-facebook-theme").tokenInput(beer, {
theme: "facebook",
propertyToSearch: "name",
preventDuplicates: true,
resultsLimit:'5',
resultsFormatter: function(item){ return "<li>" + "<img src='http://graph.facebook.com/" + item.id + "/picture' title='" + item.id + "' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.name + " </div></div></li>" },
tokenFormatter: function(item) { return "<li><p>" + item.id + "</p></li>" },
});
});
});
</script>