js json赋值

JavaScript014

js json赋值,第1张

var sjh = 123456789

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)