如何在打字稿中格式化来自http get Request的结果

拉哈特·塞尼(Rahat Saini)

我有一个有角度的项目,在这个项目中,我使用了以这种格式发送回数据的API。Head是包含用“,”分隔的所有键/属性的字符串。我想以ag-grid显示数据

   {
"Head": "Sample Number,Insurance Type,Insurance Type Name,Quote Description,NVIC,Car Detail,GNAF,Search Address,Gender,Borrowing Amount,Deposit_Amount,Loan_Term,Residual,Own_Property,Credit_Score,Vehicle_Type,Annual_Income,Loan_Type,Loan_Interest_type,Seller_Type,Error Message",
"Items": [
    "1,FCL,Finance Car Loan,Sample,MX313A,,GANT_702976160,,Male,13107,2000,5,0,No,621,Used,73200,Secured,Fixed,Private,NVIC not found.",
    "2,FCL,Finance Car Loan,Sample,N1J13A,,GANT_716848802,,Female,10630,0,5,0,No,512,Used,39600,Secured,Fixed,Private,NVIC not found.",
    "3,FCL,Finance Car Loan,Sample,01JZ18,,GANT_717255160,,Male,11429,2000,5,0,Yes,662,New,64188,Secured,Fixed,Dealer,NVIC not found.",
    "4,FCL,Finance Car Loan,Sample,MWE13A,,GANSW710285256,,Female,14483,3500,4,0,No,350,Used,40800,Secured,Fixed,Private,NVIC not found.",
}

我如何像这样{property1:value,property2:value ....}格式化来自API的响应,或者有没有办法我可以将相同格式的数据用于ag-grid

MoxxiManagarm

尝试这个

const data = {
      "Head": "Sample Number,Insurance Type,Insurance Type Name,Quote Description,NVIC,Car Detail,GNAF,Search Address,Gender,Borrowing Amount,Deposit_Amount,Loan_Term,Residual,Own_Property,Credit_Score,Vehicle_Type,Annual_Income,Loan_Type,Loan_Interest_type,Seller_Type,Error Message",
      "Items": [
          "1,FCL,Finance Car Loan,Sample,MX313A,,GANT_702976160,,Male,13107,2000,5,0,No,621,Used,73200,Secured,Fixed,Private,NVIC not found.",
          "2,FCL,Finance Car Loan,Sample,N1J13A,,GANT_716848802,,Female,10630,0,5,0,No,512,Used,39600,Secured,Fixed,Private,NVIC not found.",
          "3,FCL,Finance Car Loan,Sample,01JZ18,,GANT_717255160,,Male,11429,2000,5,0,Yes,662,New,64188,Secured,Fixed,Dealer,NVIC not found.",
          "4,FCL,Finance Car Loan,Sample,MWE13A,,GANSW710285256,,Female,14483,3500,4,0,No,350,Used,40800,Secured,Fixed,Private,NVIC not found.",
      ]
    };
const keys: string[] = data.Head.split(',');
const items = data.Items.map(item => lodash.zipObject(keys, item.split(','))); // import * as lodash from 'lodash';

导致物品被

[{"Sample Number":"1","Insurance Type":"FCL","Insurance Type Name":"Finance Car Loan","Quote Description":"Sample","NVIC":"MX313A","Car Detail":"","GNAF":"GANT_702976160","Search Address":"","Gender":"Male","Borrowing Amount":"13107","Deposit_Amount":"2000","Loan_Term":"5","Residual":"0","Own_Property":"No","Credit_Score":"621","Vehicle_Type":"Used","Annual_Income":"73200","Loan_Type":"Secured","Loan_Interest_type":"Fixed","Seller_Type":"Private","Error Message":"NVIC not found."},{"Sample Number":"2","Insurance Type":"FCL","Insurance Type Name":"Finance Car Loan","Quote Description":"Sample","NVIC":"N1J13A","Car Detail":"","GNAF":"GANT_716848802","Search Address":"","Gender":"Female","Borrowing Amount":"10630","Deposit_Amount":"0","Loan_Term":"5","Residual":"0","Own_Property":"No","Credit_Score":"512","Vehicle_Type":"Used","Annual_Income":"39600","Loan_Type":"Secured","Loan_Interest_type":"Fixed","Seller_Type":"Private","Error Message":"NVIC not found."},{"Sample Number":"3","Insurance Type":"FCL","Insurance Type Name":"Finance Car Loan","Quote Description":"Sample","NVIC":"01JZ18","Car Detail":"","GNAF":"GANT_717255160","Search Address":"","Gender":"Male","Borrowing Amount":"11429","Deposit_Amount":"2000","Loan_Term":"5","Residual":"0","Own_Property":"Yes","Credit_Score":"662","Vehicle_Type":"New","Annual_Income":"64188","Loan_Type":"Secured","Loan_Interest_type":"Fixed","Seller_Type":"Dealer","Error Message":"NVIC not found."},{"Sample Number":"4","Insurance Type":"FCL","Insurance Type Name":"Finance Car Loan","Quote Description":"Sample","NVIC":"MWE13A","Car Detail":"","GNAF":"GANSW710285256","Search Address":"","Gender":"Female","Borrowing Amount":"14483","Deposit_Amount":"3500","Loan_Term":"4","Residual":"0","Own_Property":"No","Credit_Score":"350","Vehicle_Type":"Used","Annual_Income":"40800","Loan_Type":"Secured","Loan_Interest_type":"Fixed","Seller_Type":"Private","Error Message":"NVIC not found."}]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Python中格式化JSON GET结果

来自分类Dev

如何在Webmatrix中格式化GET请求的URL

来自分类Dev

在python中格式化http get请求输出

来自分类Dev

如何在C#Excel Interop中格式化公式结果?

来自分类Dev

如何在Crystal Report中格式化公式字段的结果?

来自分类Dev

如何在C#Excel Interop中格式化公式结果?

来自分类Dev

在SQL中格式化表结果

来自分类Dev

在JFrame中格式化结果

来自分类Dev

在SQL中格式化表结果

来自分类Dev

在Bash中格式化结果

来自分类Dev

格式化来自SQL查询的结果

来自分类Dev

格式化来自SQL查询的结果

来自分类Dev

在linq查询结果中格式化日期

来自分类Dev

Laravel从数据库结果中格式化DateTime

来自分类Dev

Laravel 5.5 在 pluck 方法中格式化结果

来自分类Dev

格式化Get-WmiObject脚本的结果以匹配get-content .txt文件中的列表

来自分类Dev

如何在Angularjs的$ http.get之外访问结果

来自分类Dev

如何格式化数组的结果

来自分类Dev

如何格式化grep结果?

来自分类Dev

如何从Meteor.HTTP.Get显示结果

来自分类Dev

Http Get Request返回html?

来自分类Dev

如何在父函数中获得异步结果?打字稿

来自分类Dev

在后面的 VB.NET 代码中格式化这个 GET 请求?

来自分类Dev

选择对象Cmdlet为Get-NetIPConfiguration(不同类型)返回不同的格式化结果

来自分类Dev

格式化查询结果

来自分类Dev

request.GET.get(),它如何在Django中工作?

来自分类Dev

Angular http.get-转换结果

来自分类Dev

在返回结果之前解析 $http Get

来自分类Dev

Python-Eve:格式化对HTTP 200的GET响应