我有以下字符串從用戶進來,需要把它變成JSON。如何將此字符串轉換爲JSON對象?
2r,5g|3b,2r,4y|3g
我想用JavaScript將它轉換爲JSON。這裏是我想讓JSON看起來像:
rounds = {
"round" : {
"interval" : {
"time" : "2",
"color" : "r"
},
"interval" : {
"time" : "5",
"color" : "g"
}
},
"round" : {
"interval" : {
"time" : "3",
"color" : "b"
},
"interval" : {
"time" : "2",
"color" : "r"
},
"interval" : {
"time" : "4",
"color" : "y"
}
},
"round" : {
"interval" : {
"time" : "3",
"color" : "g"
}
}
}
我不確定從哪裏開始,所以任何幫助表示讚賞!
你想這樣做在JavaScript或服務器端像PHP這樣的語言? – Shef
代表JSON對我來說似乎無效 –
對不起,我想在JavaScript中執行此操作...我將更新該問題。 –