如何从JQuery中的JSON字符串获取JSON内容? [英] How do I get the JSON content from a JSON string in JQuery?
本文介绍了如何从JQuery中的JSON字符串获取JSON内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的JSON字符串(这是在$ .post中发出请求后得到的信息)-
My JSON string(this is what i get after making the request in $.post )-
{"email":"bill gates"}
{"email":"steve jobs"}
{"email":"mark zuckerberg"}
{"email":"cristiano ronaldo"}
{"email":"wayne rooney"}
我用来获取内容的代码-
The code I am using to get the content-
$(document).ready(function() {
var data = new Object();
data.email = "yash.mathur13@gmail.com";
var dataString = $.toJSON(data);
$.post('templates/chat.php', {
data: dataString
}, function(json) {
$("body").append(json);
});
});
我想将它们每个都放在<li>
标记中.
I want to dislay each one of them in an <li>
tag.
推荐答案
看看 http://api.jquery.com/jQuery.parseJSON/
应该能够做到
var obj = $.parseJSON(json);
$.each(obj, function(index, item){
// append to your <ul> if it already exists, or build one up
$('ul').append('<li>' + item.email + '</li>');
});
这篇关于如何从JQuery中的JSON字符串获取JSON内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文