0

我需要读取一个 csv 文件,它有一个标头和一个数据单元格,它是 JSON 格式的。需要读取 JSON 数据(从该单元格)并使用 R 将其转换为数据框。虽然我在网上找到了类似的问题,但我没有找到可行的解决方案。请帮忙。我尝试了下面的代码,但它没有用,不知道我在这里错过了什么。

install.packages("rjson")
library(rjson)

myData <- read.csv("sampleData.csv", nrows=1,skip = 1)
json_data_frame <- as.data.frame(myData)

dat_r = toJSON(myData)
dat_c = toJSON(myData)
dat_v = toJSON(myData)

该单元格中的数据:

{
  "sample": {
    "leadID": "",
    "branchID": "",
    "leadType": "",
    "fundingType": "",
    "createdDate": "",
    "outFlowDetails": [
      {
        "customersub_cat": "",
        "repayableInMonths": ,
        "amountRequested": ,
        "financeAmount": ,
        "moratorium": ,
        "emiPattern": "",
        "emiLtv": ,
        "netAssetCost": ,
        "vehicleDetail": {
          "YOM": ,
          "manufactureID": "",
          "makeID": "",
          "modelID": "",
          "schemeID": "",
          "vehicleType": "",
          "isPreDelivered": ,
          "agreementNo": "",
          "noOfOwners": 
        }
      },
      {
        "customersub_cat": "",
        "repayableInMonths": ,
        "amountRequested": ,
        "financeAmount": ,
        "moratorium": ,
        "emiPattern": "",
        "emiLtv": ,
        "netAssetCost": ,
        "vehicleDetail": {
          "YOM": ,
          "manufactureID": "",
          "makeID": "",
          "modelID": "",
          "schemeID": "",
          "vehicleType": "",
          "isPreDelivered": ,
          "agreementNo": "",
          "noOfOwners": 
        }
      }
    ],
    "priorVehicleSummary": {
      "fleetSize": ,
      "noOfFreeVehicle": ,
      "vehicleAddedLastOneYear": 
    },
    "partyDetails": [
      {
        "partyID": "",
        "partyType": "",
        "coBorrowerRelationship": "",
        "age": ,
        "customerType": "",
        "category": "",
        "negativeList": "",
        "negativeArea": "",
        "industry": "",
        "natureOfBuisness": "",
        "trustingSocialScore": "",
        "SherlockRules": [
          "",
          "",
          "",
          "",
          ""
        ],
        "documents": [
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          }
        ],
        "properties": [
          {
            "ownership": ""
          },
          {
            "ownership": ""
          }
        ],
        "occupation": {
          "businessNature": "",
          "yearsInBusiness": 
        },
        "addressDetails": [
          {
            "CurrentAddress": 
          },
          {
            "CurrentAddress": 
          },
          {
            "CurrentAddress": 
          }
        ],
        "ScoreSG_": {
          "Length": "",
          "ScoreName": "",
          "ScoreCardName": "",
          "ScoreCardVersion": "",
          "ScoreDate": "",
          "Score": "",
          "reason1FL": "",
          "reason1": "",
          "reason2FL": "",
          "reason2": "",
          "reason3FL": "",
          "reason3": "",
          "reason4FL": "",
          "reason4": "",
          "reason5FL": "",
          "reason5": ""
        },
        "acc": [
          {
            "Length": "",
            "SG_Tag": "",
            "acc_Summary_SG__Fields": {
              "ShrtNameFL": ""
            },
            "acc_NonSummary_SG__Fields": {
              "ShrtNameFL": "",
              "ShrtName": "",
              "accType": "",
              "OwnershipIndicator": "",
              "DateOpenedOrDisbursed": "",
              "DateOfLastPayment": "",
              "DateReportedAndCertified": "",
              "AmtFL": "",
              "Amt": "",
              "CB_FL": "",
              "CB_": "",
              "LastPaid1FL": "",
              "LastPaid1": "",
              "LastPaidStartDate": "",
              "LastPaidEndDate": "",
              "CL_FL": "",
              "CL_": ""
            }
          }
          
        ],
        "Enq": [
          {
            "Length": "",
            "SG_Tag": "",
            "DateOfEnqFields": "",
            "EnquiringMemberShortNameFL": "",
            "EnquiringMemberShortName": "",
            "EnqPurpose": "",
            "EnqAmountFL": "",
            "EnqAmount": ""
          }
        ]
      },
     {
        "partyID": "",
        "partyType": "",
        "coBorrowerRelationship": "",
        "age": ,
        "customerType": "",
        "category": "",
        "negativeList": "",
        "negativeArea": "",
        "industry": "",
        "natureOfBuisness": "",
        "trustingSocialScore": "",
        "SherlockRules": [
          "",
          "",
          "",
          "",
          ""
        ],
        "documents": [
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          },
          {
            "sub_cat": "",
            "ProofValue": ""
          }
        ],
        "properties": [
          {
            "ownership": ""
          },
          {
            "ownership": ""
          }
        ],
        "occupation": {
          "businessNature": "",
          "yearsInBusiness": 
        },
        "addressDetails": [
          {
            "CurrentAddress": 
          },
          {
            "CurrentAddress": 
          },
          {
            "CurrentAddress": 
          }
        ],
        "ScoreSG_": {
          "Length": "",
          "ScoreName": "",
          "ScoreCardName": "08",
          "ScoreCardVersion": "10",
          "ScoreDate": "21102020",
          "Score": "00622",
          "reason1FL": "02",
          "reason1": "04",
          "reason2FL": "02",
          "reason2": "32",
          "reason3FL": "02",
          "reason3": "28",
          "reason4FL": "02",
          "reason4": "31",
          "reason5FL": "02",
          "reason5": "29"
        },
        "acc": [
          {
            "Length": "04",
            "SG_Tag": "T001",
            "acc_Summary_SG__Fields": {
              "ShrtNameFL": "13"
            },
            "acc_NonSummary_SG__Fields": {
              "ShrtNameFL": "13",
              "ShrtName": "NOT DISCLOSED",
              "accType": "10",
              "OwnershipIndicator": "1",
              "DateOpenedOrDisbursed": "09012020",
              "DateOfLastPayment": "07082020",
              "DateReportedAndCertified": "20082020",
              "AmtFL": "05",
              "Amt": "77159",
              "CB_FL": "01",
              "CB_": "0",
              "LastPaid1FL": "21",
              "LastPaid1": "000000000XXX000000000",
              "LastPaidStartDate": "01082020",
              "LastPaidEndDate": "01022020",
              "CL_FL": "05",
              "CL_": "80000"
            }
          }
          
        ],
        "Enq": [
          {
            "Length": "04",
            "SG_Tag": "I001",
            "DateOfEnqFields": "26022020",
            "EnquiringMemberShortNameFL": "13",
            "EnquiringMemberShortName": "NOT DISCLOSED",
            "EnqPurpose": "02",
            "EnqAmountFL": "07",
            "EnqAmount": "3500000"
          }
        ]
      } 
    ]
  }
}
4

0 回答 0