var jsonstr="[{'phone':sjh}]"
var dt=eval('('+jsonstr+')')
console.log(dt) // 输出结果:[{phone:123456789}]
eval是将字符串解析成js表达式并执行
var json={"a":"aaa","b":{"c":"ccc","d":[{"e":"01","g":"kkkk"},{"e":"07","g":"lllll"},{"e":"05","g":"xxxxx"},{"e":"03","g":"kkkk"}]}}var arr=[]
for(var i=0i<json.b.d.lengthi++){
arr[i]=json.b.d[i].e+"-"+json.b.d[i].g
}
console.log(arr)
varjsonVal
=
'{"id","111","name":"小杜"}'
这样就构造了一个包含json格式的js变量,后续如果解析;需要转化为json对象
比如:var
jObject=jQuery.parseJSON(jsonVal
)
alert("id="+jObject.id)
这个值就是预期的"111"了