I have a parsed Json string that i would like to further split into 4 different arrays. I have tried using $.parseJson('[' + data + ']');
which returns all of the data into a single array. More Precisely i need it to look more like catData = [Object, Object, Object, Object]
Thanks for your help.
我有一个解析的Json字符串,我想进一步分成4个不同的数组。我尝试过使用$ .parseJson('['+ data +']');它将所有数据返回到一个数组中。更准确地说,我需要它看起来更像catData = [对象,对象,对象,对象]感谢您的帮助。
my data coming in looks like this
我的数据看起来像这样
[{\"LkpMasterID\":491,\"LkpMasterCode\":\"CAT INSURANCE\",\"LkpMasterDescription\":\"25\",\"Attribute\":\"Cat Values\",\"Dependency\":null,\"LkpName\":\"CAT INSURANCE\",\"IsAttribute\":false,\"IsActive\":true,\"CreatedBy\":52834,\"CreatedOn\":\"2015-09-15T15:25:46.273\",\"UpdatedBy\":null,\"UpdatedOn\":null,\"IsDeleted\":false,\"ProcessedPage\":\"Master.aspx\",\"DisplayOrder\":1},{\"LkpMasterID\":492,\"LkpMasterCode\":\"CAT SUPPLEMENTS\",\"LkpMasterDescription\":\"50\",\"Attribute\":\"Cat Values\",\"Dependency\":null,\"LkpName\":\"CAT SUPPLEMENTS\",\"IsAttribute\":false,\"IsActive\":true,\"CreatedBy\":52834,\"CreatedOn\":\"2015-09-15T15:28:36.2\",\"UpdatedBy\":56366,\"UpdatedOn\":\"2015-09-16T10:26:36.95\",\"IsDeleted\":false,\"ProcessedPage\":\"Master.aspx\",\"DisplayOrder\":2},{\"LkpMasterID\":493,\"LkpMasterCode\":\"OTHER CATS\",\"LkpMasterDescription\":\"30\",\"Attribute\":\"Cat Values\",\"Dependency\":null,\"LkpName\":\"OTHER CATS\",\"IsAttribute\":false,\"IsActive\":true,\"CreatedBy\":56366,\"CreatedOn\":\"2015-09-16T10:27:37.777\",\"UpdatedBy\":null,\"UpdatedOn\":null,\"IsDeleted\":false,\"ProcessedPage\":\"Master.aspx\",\"DisplayOrder\":3},{\"LkpMasterID\":495,\"LkpMasterCode\":\"SHORT-TERM CATS\",\"LkpMasterDescription\":\"30\",\"Attribute\":\"CAT Values\",\"Dependency\":null,\"LkpName\":\"SHORT-TERM CATS\",\"IsAttribute\":false,\"IsActive\":true,\"CreatedBy\":56366,\"CreatedOn\":\"2015-10-02T00:00:00\",\"UpdatedBy\":null,\"UpdatedOn\":null,\"IsDeleted\":false,\"ProcessedPage\":\"Master.aspx\",\"DisplayOrder\":4}]"
$.getJson('LkpMasterTable', function (data) { var catData = JSON.Parse(data)) }
var catData = [
{"LkpMasterID":491,"LkpMasterCode":"CAT INSURANCE","LkpMasterDescription":"25","Attribute":"Cat Values","Dependency":null,"LkpName":"CAT INSURANCE","IsAttribute":false,"IsActive":true,"CreatedBy":52834,"CreatedOn":"2015-09-15T15:25:46.273","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":1},
{"LkpMasterID":492,"LkpMasterCode":"CAT SUPPLEMENTS","LkpMasterDescription":"50","Attribute":"Cat Values","Dependency":null,"LkpName":"CAT SUPPLEMENTS","IsAttribute":false,"IsActive":true,"CreatedBy":52834,"CreatedOn":"2015-09-15T15:28:36.2","UpdatedBy":56366,"UpdatedOn":"2015-09-16T10:26:36.95","IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":2},
{"LkpMasterID":493,"LkpMasterCode":"OTHER CATS","LkpMasterDescription":"30","Attribute":"Cat Values","Dependency":null,"LkpName":"OTHER CATS","IsAttribute":false,"IsActive":true,"CreatedBy":56366,"CreatedOn":"2015-09-16T10:27:37.777","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":3},
{"LkpMasterID":495,"LkpMasterCode":"SHORT-TERM CATS","LkpMasterDescription":"30","Attribute":"Cat Values","Dependency":null,"LkpName":"SHORT-TERM CATS","IsAttribute":false,"IsActive":true,"CreatedBy":56366,"CreatedOn":"2015-10-02T00:00:00","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":4}
]
1 个解决方案
#1
3
What you can do is use jQuery's map function to "Translate all items in an array or object to new array of items."
你可以做的是使用jQuery的map函数“将数组或对象中的所有项目转换为新的项目数组”。
var catData = [
{"LkpMasterID":491,"LkpMasterCode":"CAT INSURANCE","LkpMasterDescription":"25","Attribute":"Cat Values","Dependency":null,"LkpName":"CAT INSURANCE","IsAttribute":false,"IsActive":true,"CreatedBy":52834,"CreatedOn":"2015-09-15T15:25:46.273","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":1},
{"LkpMasterID":492,"LkpMasterCode":"CAT SUPPLEMENTS","LkpMasterDescription":"50","Attribute":"Cat Values","Dependency":null,"LkpName":"CAT SUPPLEMENTS","IsAttribute":false,"IsActive":true,"CreatedBy":52834,"CreatedOn":"2015-09-15T15:28:36.2","UpdatedBy":56366,"UpdatedOn":"2015-09-16T10:26:36.95","IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":2},
{"LkpMasterID":493,"LkpMasterCode":"OTHER CATS","LkpMasterDescription":"30","Attribute":"Cat Values","Dependency":null,"LkpName":"OTHER CATS","IsAttribute":false,"IsActive":true,"CreatedBy":56366,"CreatedOn":"2015-09-16T10:27:37.777","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":3},
{"LkpMasterID":495,"LkpMasterCode":"SHORT-TERM CATS","LkpMasterDescription":"30","Attribute":"Cat Values","Dependency":null,"LkpName":"SHORT-TERM CATS","IsAttribute":false,"IsActive":true,"CreatedBy":56366,"CreatedOn":"2015-10-02T00:00:00","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":4}
]
var arr = $.map(catData, function(x) { return x; })
console.log(arr)
The results of using map look like 'catData = [Object, Object, Object, Object]'.
使用map的结果看起来像'catData = [Object,Object,Object,Object]'。
#1
3
What you can do is use jQuery's map function to "Translate all items in an array or object to new array of items."
你可以做的是使用jQuery的map函数“将数组或对象中的所有项目转换为新的项目数组”。
var catData = [
{"LkpMasterID":491,"LkpMasterCode":"CAT INSURANCE","LkpMasterDescription":"25","Attribute":"Cat Values","Dependency":null,"LkpName":"CAT INSURANCE","IsAttribute":false,"IsActive":true,"CreatedBy":52834,"CreatedOn":"2015-09-15T15:25:46.273","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":1},
{"LkpMasterID":492,"LkpMasterCode":"CAT SUPPLEMENTS","LkpMasterDescription":"50","Attribute":"Cat Values","Dependency":null,"LkpName":"CAT SUPPLEMENTS","IsAttribute":false,"IsActive":true,"CreatedBy":52834,"CreatedOn":"2015-09-15T15:28:36.2","UpdatedBy":56366,"UpdatedOn":"2015-09-16T10:26:36.95","IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":2},
{"LkpMasterID":493,"LkpMasterCode":"OTHER CATS","LkpMasterDescription":"30","Attribute":"Cat Values","Dependency":null,"LkpName":"OTHER CATS","IsAttribute":false,"IsActive":true,"CreatedBy":56366,"CreatedOn":"2015-09-16T10:27:37.777","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":3},
{"LkpMasterID":495,"LkpMasterCode":"SHORT-TERM CATS","LkpMasterDescription":"30","Attribute":"Cat Values","Dependency":null,"LkpName":"SHORT-TERM CATS","IsAttribute":false,"IsActive":true,"CreatedBy":56366,"CreatedOn":"2015-10-02T00:00:00","UpdatedBy":null,"UpdatedOn":null,"IsDeleted":false,"ProcessedPage":"Master.aspx","DisplayOrder":4}
]
var arr = $.map(catData, function(x) { return x; })
console.log(arr)
The results of using map look like 'catData = [Object, Object, Object, Object]'.
使用map的结果看起来像'catData = [Object,Object,Object,Object]'。