我得到的数据,像一个URL“/系统/人/ 3”,我怎么可以转换(见底部JSON)与jQuery和制造类似:$(".name").(data.name);
我需要把它放在一个div ...JSON字符串转换为jQuery的JavaScript对象?
{
"id": 1,
"name": "George X.",
"description": "test 1sdfasdfasdf",
"birthday": "2017-10-01 00:00:00"
}
我得到的数据,像一个URL“/系统/人/ 3”,我怎么可以转换(见底部JSON)与jQuery和制造类似:$(".name").(data.name);
我需要把它放在一个div ...JSON字符串转换为jQuery的JavaScript对象?
{
"id": 1,
"name": "George X.",
"description": "test 1sdfasdfasdf",
"birthday": "2017-10-01 00:00:00"
}
我想如果你特别想要的jQuery:
$.getJSON("test.json", function(json) {
$(".name").html(json);
});
var data = JSON.parse(jsonString); // parse JSON string
$('.name').html(data.name); // select element and update its content
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
可以解析响应与JSON.parse
var data = JSON.parse(profileResponse);
或者您可以发送请求$.getJSON
,该请求会自动解析响应,并将作为JavaScript对象提供。
使用JSON.parse()
功能
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
这可以放置网址来获取数据? – nowilius
@nowilius:了解Ajax:https://api.jquery.com/jquery.ajax/ –
点击一个url可能会导致异步操作,这可以通过AJAX最好地处理。您应该使用AJAX从网址获取数据 –
使用你给我们的JSON,你可以张贴输出的_actual_比如你要 –