如何在AngularJS中追加Json String

时间:2014-10-08 18:23:29

标签: javascript json angularjs

所以这是我的Json String

   {
      "method_name": "WSP.CC.GET.CARRIER.INFO",
      "calling_class": "com.fwdco.webservice.ScorpeoWebService",
      "error_code": "0",
      "contact_info": [
        [
          "name",
          "email",
          "phone"
        ]
      ]
    }

如果我想插入

           [
             "man"
             "man@yahoo.com"
             "534534646"
            ]

在contact_info中,以便最终的json String为:

         {
  "method_name": "WSP.CC.GET.CARRIER.INFO",
  "calling_class": "com.fwdco.webservice.ScorpeoWebService",
  "error_code": "0",
  "contact_info": [
    [
      "name",
      "email",
      "phone"
    ],
    [
       "man"
       "man@yahoo.com"
       "534534646"
     ]
  ]
}

我试图使用拼接和推送功能,但它不起作用。 帮助PLZ

2 个答案:

答案 0 :(得分:1)

尝试一下这个:http://jsfiddle.net/csdtesting/97mvba88/

var obj = {
  "method_name": "WSP.CC.GET.CARRIER.INFO",
  "calling_class": "com.fwdco.webservice.ScorpeoWebService",
  "error_code": "0",
  "contact_info": [
    [
      "name",
      "email",
      "phone"
    ]
  ]

};


obj.contact_info.push(["man", "man@yahoo.com", '534534646']);
console.log(obj);
console.log(obj.contact_info);

答案 1 :(得分:0)

如果您使用的是JavaScript,这是一个解决方案:

var myObject = {
    "method_name": "WSP.CC.GET.CARRIER.INFO",
    "calling_class": "com.fwdco.webservice.ScorpeoWebService",
    "error_code": "0",
    "contact_info": [
         [
           "name",
           "email",
           "phone"
         ]
    ]
};

myObject.contact_info.push([
  "man",
  "man@yahoo.com",
  "534534646"
]);