Json文件格式为R中的CSV

时间:2019-12-12 05:39:32

标签: r json csv

我有.log扩展名示例数据的JSON格式文件如下    “标题”:{         “ systemId”:“ WsCrgenstd_RTM_74”,         “ sourceSystemType”:“自定义”       },       “身体”: {         “ systemId”:“ WsCrgenstd_RTM_74”,         “ createTimestamp”:“ 1575284734366”,         “ stringPoints”:[]       }     }

  "header": {
    "systemId": "WsCrgenstd_RTM_74",
    "sourceSystemType": "CUSTOM"
  },
  "body": {
    "systemId": "WsCrgenstd_RTM_74",
    "createTimestamp": "1575284734631",
    "stringPoints": []
  }
}

  "header": {
    "systemId": "WsCrgenstd_RTM_74",
    "sourceSystemType": "CUSTOM"
  },
  "body": {
    "systemId": "WsCrgenstd_RTM_74",
    "createTimestamp": "1575284735224",
    "stringPoints": [
      {
        "name": "空调主机/电机线圈温度2/主机1",
        "dataTimestamp": 1575284700000,
        "value": "13.2599992752075",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "空调主机/电机线圈温度2/主机2",
        "dataTimestamp": 1575284700000,
        "value": "5.87747175411144E-39",
        "status": "OK",
        "pointType": "STRING"
      }
    ]
  }
}

  "header": {
    "systemId": "WsCrgenstd_RTM_74",
    "sourceSystemType": "CUSTOM"
  },
  "body": {
    "systemId": "WsCrgenstd_RTM_74",
    "createTimestamp": "1575284735364",
    "stringPoints": [
      {
        "name": "末端空调箱/风机运行状态/AHU_1_1",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "末端空调箱/风机运行状态/AHU_1_2",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "末端空调箱/风机运行状态/AHU_1_3",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "末端空调箱/风机运行状态/AHU_1_4",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "末端空调箱/风机运行状态/AHU_2_1",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "末端空调箱/风机运行状态/AHU_2_2",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "末端空调箱/风机运行状态/AHU_2_3",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      },
      {
        "name": "末端空调箱/风机运行状态/AHU_2_4",
        "dataTimestamp": 1575284700000,
        "value": "0",
        "status": "OK",
        "pointType": "STRING"
      }
    ]
  }
}

我想使用R将其转换为CSV文件格式。有人可以帮助我阅读文件并将其转换。 我的输出应如下图enter image description here

所示

1 个答案:

答案 0 :(得分:0)

您可以使用下面的代码,这将有助于将Json转换为csv文件。 我不确定您在此处发布的内容是否是确切的json。 但一定会有帮助。

d1 <- fromJSON(r1,simplifyVector = TRUE)

write.csv(d1,'mydata.csv',rows.name=F)

其中r1是您的json文件 d1是您的数据框, 最终的csv文件是mydata,如果执行命令write.csv,它可以保存在目录中。