以這一行為範例的話
var nli_obj = JSON.parse(JSON.stringify(serverResponse));
輸出:
除錯: {"data":{"nli":[{"desc_obj":{"status":0},"semantic":[{"app":"weather","input":"今天天氣如何","slots":[{"datetime":{"data":{"start_time":1565539200000,"end_time":1565625600000},"type":"time_recommend"},"name":"time","value":"今天"}],"modifier":["query"],"customer":"5cd8236ae4b039274c0daa46"}],"type":"weather"}]},"status":"ok"}
想請教我該如何取出slots中的value呢?
學粗才淺的,非常不好意思><
const jsonData = { 除錯: { ... }};
console.log(jsonData.除錯.data.nli[0].semantic[0].slots);
他說他要的是 slots中的value,會不會是指這個?
"value":"今天"
console.log(jsonData.除錯.data.nli[0].semantic[0].slots[0]['value']);
這就要看他的 value 是 名詞 還是 代名詞 了 XD
抱歉沒有說清楚,的確是當中slots中的value,非常感謝你們~
不過蠻好奇的是,為什麼會需要那個0呢?
因為他是陣列呀
你把他攤開來看就知道了
除錯: {
"data": {
"nli": [
{
"desc_obj": {
"status": 0
},
"semantic": [
{ "app": "weather",
"input": "今天天氣如何",
"slots": [
{
"datetime": {
"data": {
"start_time": 1565539200000,
"end_time": 1565625600000
},
"type": "time_recommend"
},
"name": "time",
"value":"今天"
}
],
"modifier": ["query"],
"customer": "5cd8236ae4b039274c0daa46"
}
],
"type":"weather"
}
]
},
"status":"ok"
}
感謝你,之前都沒想到這個><