我怎么能在jQuery中读到这个?

时间:2014-02-09 18:29:08

标签: javascript jquery json

有人可以帮我在jQuery中读取这个回调数组吗?

{ 
  "message-count":1, 
  "error-text": "Invalid Phone format. Please ensure phone number to be in international format. e.g 447876567655." 
} 

2 个答案:

答案 0 :(得分:4)

您可以使用JSON.parse()$.each()

var a=JSON.parse('{ "message-count":1, "error-text":"Invalid Phone format. Please ensusure phone number to be in international format. e.g 447876567655 ." } ');

$.each(a,function(i,v){
   console.log(i+':'+v);
})

Demo

答案 1 :(得分:3)

你的是JSON回复,只需使用Bracket notation

var data = { "message-count":1, "error-text":"Invalid Phone format. Please ensusure phone number to be in international format. e.g 447876567655 ." };
alert(data['message-count']);

DEMO