我有一些JSON已從servlet傳遞並存儲在xmlhttp.responseText中。我想分解這個JSON,以便我可以擁有數據,大小,樣式,名稱等的值。另外,我希望將小部件值設置爲單獨的變量。JavaScript中的JSON字符串解析
這裏是JSON:
{
"widget vlaue=2": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity/100) * 90;"
}
}
我已經試過這樣:
obj = JSON.parse(xmlhttp.responseText);
但失敗了。我在網上找不到與它相關的任何內容。任何人都可以幫助我嗎?
你是什麼意思,它「失敗」?你有沒有從瀏覽器中得到任何錯誤? –
這個輸出是「undefined」 – typedefcoder2
你的意思是「輸出是'未定義'這個」?什麼是'這個'和'輸出'是什麼? –