2017-08-18 12:30
浏览 25


enter image description here Input: var result= JSON.parse(response); console.log(result);

Given below is the output of console.log(result); Now i want to convert this into given below output i want like this.

  {day: Array(7), amount: Array(7)}
  amount: (7) [413, 14, 2, 37, 50, 22, 82]
  day: (7) ["02-Jan-16", "03-Jan-16", "04-Jan-16", "05-Jan-16", "06-Jan-16", 
  "07-Jan-16", "08-Jan-16"]

 This input is ajax response data. Now i  want to convert this response data 
 into a particular format which i describe below. My output should look like 
 this. How can i do this?

 Output I want:

 [[02-Jan-16,413],[03-Jan-16,14],[04-Jan-16,2],[05-Jan-16,37], [06-Jan-

enter image description here This is the output image. check it out.

图片转代码服务由CSDN问答提供 功能建议

在此输入图像描述输入: var result = JSON.parse(response); console.log(result);

以下是console.log(result)的输出; 现在我想将此转换为下面的输出,我希望这样。

金额:(7)[413,14,2,37,50  ,22,82] 
 day:(7)[“02-Jan-16”,“03-Jan-16”,“04-Jan-16”,“05-Jan-16”,“06-Jan-  16“,
此输入是ajax响应数据。 现在我想将此响应数据
转换为我在下面描述的特定格式。 我的输出应该看起来像
。 我该怎么做?
 [[02-Jan-16,413],[03-Jan-16,14],[04-Jan-16,2],[  05-Jan-16,37],[06-Jan- 

在此输入图像说明 这是输出图像 。 看看吧。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyan1244 2017-08-18 12:37

    You could map the wanted values for a new array.

    function getData(object) {
        return data.amount.map(function(a, i) {
            return [object.day[i], a];
    var data = {
            amount: [413, 14, 2, 37, 50, 22, 82],
            day: ["02-Jan-16", "03-Jan-16", "04-Jan-16", "05-Jan-16", "06-Jan-16", "07-Jan-16", "08-Jan-16"]
        result = getData(data);
    .as-console-wrapper { max-height: 100% !important; top: 0; }

    点赞 评论
  • dthok9648 2017-08-18 12:42

    First you have to decide in which language you want to do the json coding PHP or JavaScript? There are inbuilt functions available in both the languages, first you should be comfortable with Nested Array, once you understand the Array construction then its just a few minutes job to form expected JSON format using inbuilt functions.

    Please don't expect code from us when already plenty of information is available on web, just google it.

    点赞 评论

相关推荐 更多相似问题