如何将字符串转换为json对象?

时间:2010-05-06 18:08:48

标签: javascript ajax json

我使用发送回字符串的ajax ..

我想将responsetext转换为要处理的json对象。

我尝试了eval,但也没有用......

该做什么?

我的代码是

function handleResponse() {
  if(httpa.readyState == 4){
  var response = httpa.responseText;
    if(response!='empty')
    {
      alert(response);  
      var foo = eval('(' +strJSON+ ')');
      alert (foo);
    }
}
}

//回复提醒

[{"id":"1","name":"Pepsodent 100g","selling_price":"28.75"},{"id":"2","name":"Pepsodent 40g","selling_price":"18.90"},{"id":"3","name":"Pepsodent brush","selling_price":"19.50"}]

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

strJSON更改为response