Reputation: 29
I have a JSON data that contains chinese characters which looks like this:
output = [{"name":"姓名"},{"name":"年齡"},{"name":"地址"}]
and I try to do the following:
var method = JSON.parse(output);
$.each(method, function(name, value) {
alert(value.method);
}
Instead of returning 姓名, 年齡, and 地址, it returns undefined, undefined and undefined.
Any idea or help will be much appreciated! Thank you all in advance!
Upvotes: 1
Views: 1844
Reputation: 1333
jQuery.each( collection, callback(indexInArray, valueOfElement) )
you miss the api of each()
var method = JSON.parse(output);
$.each(method, function(name, value) {
alert(value.name); // value is an object {name: "地址"}
}
http://api.jquery.com/jQuery.each/
Upvotes: 1