-1
Javascriptを使用して大きなJSONを検索する必要があります。その後、私はこのライブラリdefiantjsを見つけました。私は特定の製品を検索しようとしています&すべての製品をレスポンスとして再試行します。defiantjsを使用してJSONを検索する方法 - Javascript
例:
シャンプーを検索する必要がある場合。レスポンスは、JSONArray内のすべてのシャンプー製品を返す必要があります。
他のライブラリを使用する必要があるのか、このライブラリが使用できるのかを教えてください。
<html>
<head>
<title>Shopper Search</title>
<script src="./defiant.min.js" type="text/javascript" /></script>
<script>
var data = {
"Products": {
"C01M01P001": {
"productBuyingPrice": "",
"productCID": "C01",
"productDescription": "3 Roses Mind Sharp Tea 250 gms..",
"productID": "C01M01P001",
"productImage": "http://www.the.com/image/cache/Product_Images/3RosesMindSharp250g-500x500.jpg",
"productMID": "M01",
"productMRP": "160.00",
"productName": "3 Roses Mind Sharp Tea",
"productSID": "",
"productSellingPrice": "",
"productStatus": false,
"productUnit": "250 gms",
"wholesalePrice": ""
},
"C09M01S01P032": {
"productBuyingPrice": "",
"productCID": "C09",
"productDescription": "Dove Hairfall Rescue Shampoo 180 ml..",
"productID": "C09M01S01P032",
"productImage": "http://www.the.com/image/cache/Product_Images_2016/20160517-IMG_4918-500x500.jpg",
"productMID": "M01",
"productMRP": "160.00",
"productName": "Dove Hairfall Rescue Shampoo",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "180 ml",
"wholesalePrice": ""
},
"C09M01S01P020": {
"productBuyingPrice": "",
"productCID": "C09",
"productDescription": "Clinic Plus Strong & Long Health Shampoo 30 ml..",
"productID": "C09M01S01P020",
"productImage": "http://www.the.com/image/cache/Product_Images_2016/20160525-IMG_5100-500x500.jpg",
"productMID": "M01",
"productMRP": "10.00",
"productName": "Clinic Plus Strong & Long Health Shampoo",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "30 ml",
"wholesalePrice": ""
},
"C09M01S03P012": {
"productBuyingPrice": "",
"productCID": "C09",
"productDescription": "Dabur Amla Hair Oil 90 ml..",
"productID": "C09M01S03P012",
"productImage": "http://www.the.com/image/cache/Product_Images_2016/daburamlahairoilomi-500x500.jpg",
"productMID": "M01",
"productMRP": "42.00",
"productName": "Dabur Amla Hair Oil",
"productSID": "S03",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "90 ml",
"wholesalePrice": ""
},
"C09M01S01P102": {
"productBuyingPrice": "",
"productCID": "C09",
"productDescription": "Pantene Shampoo Anti-Dandruff 180 ml..",
"productID": "C09M01S01P102",
"productImage": "http://www.the.com/image/cache/Product_Images_2016/20160524-IMG_5051-500x500.jpg",
"productMID": "M01",
"productMRP": "155.00",
"productName": "Pantene Shampoo Anti-Dandruff",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "180 ml",
"wholesalePrice": ""
},
"C08M07S01P012": {
"productBuyingPrice": "",
"productCID": "C08",
"productDescription": "Tiger Rose Essence 20 ml..",
"productID": "C08M07S01P012",
"productImage": "http://www.the.com/image/cache/Product_Images/1724_tiger-500x500.jpg",
"productMID": "M07",
"productMRP": "23.00",
"productName": "Tiger Rose Essence",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "20 ml",
"wholesalePrice": ""
},
"C08M02S01P049": {
"productBuyingPrice": "",
"productCID": "C08",
"productDescription": "Britannia Treat - Jim Jam Biscuits 100 gms..",
"productID": "C08M02S01P049",
"productImage": "http://www.the.com/image/cache/Product_Images_2016/treat-jim-jam-500x500.png",
"productMID": "M02",
"productMRP": "20.00",
"productName": "Britannia Treat - Jim Jam Biscuits",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "100 gms",
"wholesalePrice": ""
},
"C07M05S01P002": {
"productBuyingPrice": "",
"productCID": "C07",
"productDescription": "Cycle Three in One Agarbathis 138 gms..",
"productID": "C07M05S01P002",
"productImage": "http://www.the.com/image/cache/Product_Images_2016/20160314-IMG_8135-500x500.jpg",
"productMID": "M05",
"productMRP": "50.00",
"productName": "Cycle Three in One Agarbathis",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "138 gms",
"wholesalePrice": ""
},
"C06M02S01P001": {
"productBuyingPrice": "",
"productCID": "C06",
"productDescription": "Annachi Poo - Star Anise - Phool Chakri 10 gms..",
"productID": "C06M02S01P001",
"productImage": "http://www.the.com/image/cache/Product_Images/shutterstock_228810289_anachipoo-500x500.jpg",
"productMID": "M02",
"productMRP": "10.00",
"productName": "Annachi Poo - Star Anise - Phool Chakri (சோம்பு)",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "10 gms",
"wholesalePrice": ""
},
"C08M01S01P007": {
"productBuyingPrice": "",
"productCID": "C08",
"productDescription": "Kellogs Chocos Crunchy Bites 390 gms..",
"productID": "C08M01S01P007",
"productImage": "http://www.the.com/image/cache/Product_Images/kellogschocoscrunchybites-500x500.jpg",
"productMID": "M01",
"productMRP": "165.00",
"productName": "Kellogg's Chocos Crunchy Bites",
"productSID": "S01",
"productSellingPrice": "",
"productStatus": true,
"productUnit": "390 gms",
"wholesalePrice": ""
}
}
};
var snapshot = Defiant.getSnapshot(data);
// Snapshot search - this is more than 100 times faster than 'regular search'
// //*/productName["Star"]/productName
found = JSON.search(snapshot, '//*productName["shampoo"]');
console.log(found);
</script>
</head>
<body>
</body>
</html>
出力のみが商品名を示しています。しかし、3つのJSONオブジェクトを1つのJsonarrayでどのように返すことができますか? – user3467240