Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Angular(typescript)中向JSON对象添加新的键数组?_Json_Angular_Typescript - Fatal编程技术网

如何在Angular(typescript)中向JSON对象添加新的键数组?

如何在Angular(typescript)中向JSON对象添加新的键数组?,json,angular,typescript,Json,Angular,Typescript,我已经尝试寻找解决方案,但我发现最接近的方法是添加一个带有值的简单键 我有一个Json对象: { "answers": [ { "phrase": "Why?", "nextIntentId": "4a10fd2b-bc6b-4563-8d97-34ef6dec1ba9" }, { "phras

我已经尝试寻找解决方案,但我发现最接近的方法是添加一个带有值的简单键

我有一个Json
对象

 {
    "answers": [
      {
        "phrase": "Why?",
        "nextIntentId": "4a10fd2b-bc6b-4563-8d97-34ef6dec1ba9"
      },
      {
        "phrase": "Faster recovery?",
        "nextIntentId": "4f9eeecf-6477-435b-9f1b-43304748a4e5"
      }
    ],
    "intentId": "19f458e8-ce1f-43eb-beb8-b8ef4e7ff4c7"
  }
我想向这个对象添加一个数组:
“消息”:[]

这个想法是,之后我可以
intent.messages.push(object)
对象到这个数组,就像
中的“answers”:[]
数组一样

 {
    "answers": [
      {
        "phrase": "Why?",
        "nextIntentId": "4a10fd2b-bc6b-4563-8d97-34ef6dec1ba9"
      },
      {
        "phrase": "Faster recovery?",
        "nextIntentId": "4f9eeecf-6477-435b-9f1b-43304748a4e5"
      }
    ],
    "intentId": "19f458e8-ce1f-43eb-beb8-b8ef4e7ff4c7",
    "messages" : []                            <<------------ I want to add this aray
  }
{
“答案”:[
{
“短语”:“为什么?”,
“NEXTINENTID”:“4a10fd2b-bc6b-4563-8d97-34ef6dec1ba9”
},
{
“短语”:“更快的恢复?”,
“NEXTINENTID”:“4f9eeecf-6477-435b-9f1b-43304748a4e5”
}
],
“意向书”:“19f458e8-ce1f-43eb-beb8-b8ef4e7ff4c7”,

“消息”:[]您可以直接将值设置为空白数组:


this.intent.messages=[];
intent.messages=[]
?我强烈建议在尝试将TypeScript和Angular API堆叠在其上之前先查看基本JS。谢谢,我会这样做的!
intent.messages=[]//这可能是由于Angular中的编译错误“因为对象上不存在消息”
intent['messages']=[]
//无错误`