2015-10-20 8 views
5

私はさらに4つの異なる配列に分割したいと考えている解析されたJson文字列を持っています。私は$.parseJson('[' + data + ']');を使用してみましたが、すべてのデータを1つの配列に返します。より正確に私はより多くのように見える必要がありますcatData = [Object, Object, Object, Object]あなたの助けをありがとう。あなたがするjQueryのmap functionを使用している何ができるか、この解析されたJSON文字列から4つの配列を作成します

[{\"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} 
    ] 
+0

あなたが得る正確な生のJSONは何ですか? –

+0

FYI、 'getJson'はJSONデータを返します。これは再び解析する必要はありません – Tushar

+1

' $ .getJson'は '$ .getJSON'になります – charlietfl

答えて

3

FIDDLE

のようなルックスに来

私のデータ「項目の新しい配列に配列またはオブジェクト内のすべての項目を翻訳します。」

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) 

'catData = [オブジェクト、オブジェクト、オブジェクト、オブジェクト]' のような地図の外観を使用するresults

+0

正確にはこれのポイントは何ですか? 'catData'と' arr'は、あなたが識別関数を使用しているのでまったく同じように見えます。ここで '$ .map'の目的を理解しているかわかりません。 OPがこれを受け入れるという事実は、それが解決策を理解していないか、質問で説明されているものとは非常に異なる何かを望んでいることを意味します。配列の浅いコピーをしたい場合は、 'var arr = catData.slice(0);'が簡単になります。 –

関連する問題