You have a string representing a JSON serialized JavaScript object.(您有一个表示JSON序列化JavaScript对象的字符串。)
You need to deserialize it back to a JavaScript object before being able to loop through its properties.(在能够遍历其属性之前,需要将其反序列化为JavaScript对象。) Otherwise you will be looping through each individual character of this string.(否则,您将循环遍历此字符串的每个单独字符。)
var resultJSON = '{"FirstName":"John","LastName":"Doe","Email":"[email protected]","Phone":"123 dead drive"}';
var result = $.parseJSON(resultJSON);
$.each(result, function(k, v) {
//display the key and value pair
alert(k + ' is ' + v);
});
Live demo .(现场演示 。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…