如何将[object Object]保存在mysql表中

时间:2018-06-24 01:42:07

标签: json

我正在读取JSON文件,并从中提取信息。这是一个示例:

 "mediaFiles": [{
  "mediaUri": "some.mp3",
  "mediaPath": "something.mp3",
  "startTime": "2018-05-09T03:04:22.000 0000",
  "stopTime": "2018-05-09T03:04:31.000 0000",
  "callUUID": "something",
  "mediaId": "something.mp3.bin",
  "type": "audio/mp3",
  "duration": "9255",
  "tenant": "Environment",
  "ivrprofile": "Record",
  "size": "18144",
  "parameters": {
    "dateTime": "2018-05-09T03:04:47Z",
    "uniqueId": "J2KV33MUT53JTBG0U73CDKC7QS000006",
    "from": "1002",
    "id": "J2KV33MUT53JTBG0U73CDKC7QS000006_2018-05-09_03-04-47_",
    "to": "1001",
    "usered": "Agent2N@somewhere.com"
  },
  "pkcs7": ".. values ...",
  "certAlias": [" ... values....],
  "partitions": [],
  "accessgroups": ["/myagents"]
}],

一切都很好,直到我到达 Parameters 对象。我有另一个很高兴地提取它们的过程,但是我找不到在mediafiles数组中排除它们的方法。这是我的操作方式的一个片段:

      for (num in J.recordings[x].mediaFiles) {
      mediavalue += Object.values(J.recordings[x].mediaFiles[num]) + 
 "),";
      mediavalue.replace(",[object Object],", ",");
      for (numpara in J.recordings[x].mediaFiles[num].parameters) {
    paradata += "'" + J.recordings[x].mediaFiles[num].parameters[numpara] + "',";

  }
  paradata = paradata.slice(0, -1);
  paradata += temppara;
  savepara(paradata);
}


mediadata += mediavalue;
//   mediadata.slice(12);
// tried to exclude parameters... didnt work
savemedia(mediadata);

我需要获取mediaFiles kvp中的所有值,并将它们放入插入语句中以保存到MySQL。但是,参数显示为[object Object]。我尝试排除它们,替换它们,现在我试图将它们另存为一个斑点。

1 个答案:

答案 0 :(得分:0)

也许您需要在发送前使用JSON.stringify转换为JSON:

savemedia(JSON.stringify(mediadata));