2013-03-28 106 views
0

我煎茶觸摸應用程式,例如這是我的JSON數據,解析JSON數據categorywise

{ 
    "type": "FeatureCollection", 
    "features": [ 
{ 
    "type": "Feature", 
    "id": "rodos_business_pois.1", 
    "geometry": { 
    "type": "Point", 
    "coordinates": [ 
     28.21962354993591, 
     36.452844361147314 
    ] 
    }, 
    "geometry_name": "geom", 
    "properties": { 
    "id": null, 
    "business_p": "AQUARIOUM", 
    "name_owner": null, 
    "surname_ow": null, 
    "middle_nam": null, 
    "category_n": "BAR", 
    "category_c": "020200", 
    "category_1": null, 
    "category_2": null, 
    "category_3": null, 
    "address": "28 GRIVA GEORGIOU", 
    "street_nam": "ÃÑÉÂÁ ÃÅÙÑÃÉÏÕ", 
    "number": "28", 
    "postcode": null, 
    "places_en_": "RODOS", 
    "f16": 1, 
    "f17": 0, 
    "tel": 2.24102778E9, 
    "fax": 0, 
    "mob": 0, 
    "email": null, 
    "url": null, 
    "places_gr": null, 
    "places_en": null 
    } 
}, 
{ 
    "type": "Feature", 
    "id": "rodos_business_pois.2", 
    "geometry": { 
    "type": "Point", 
    "coordinates": [ 
     28.225417523605692, 
     36.436470953176716 
    ] 
    }, 
    "geometry_name": "geom", 
    "properties": { 
    "id": null, 
    "business_p": "ZIGOS", 
    "name_owner": null, 
    "surname_ow": null, 
    "middle_nam": null, 
    "category_n": "BAR", 
    "category_c": "020200", 
    "category_1": null, 
    "category_2": null, 
    "category_3": null, 
    "address": "89 KAZOULI STEFANOU", 
    "street_nam": "ÊÁÆÏÕËÇ ÓÔÅÖÁÍÏÕ", 
    "number": "89", 
    "postcode": null, 
    "places_en_": "RODOS", 
    "f16": 1, 
    "f17": 0, 
    "tel": 2.24103987E9, 
    "fax": 0, 
    "mob": 0, 
    "email": null, 
    "url": null, 
    "places_gr": null, 
    "places_en": null 
    } 
}, 
{ 
    "type": "Feature", 
    "id": "rodos_business_pois.3", 
    "geometry": { 
    "type": "Point", 
    "coordinates": [ 
     28.223100266167258, 
     36.45251556942936 
    ] 
    }, 
    "geometry_name": "geom", 
    "properties": { 
    "id": null, 
    "business_p": "LA ROSA FASHION BAR", 
    "name_owner": null, 
    "surname_ow": null, 
    "middle_nam": null, 
    "category_n": "BAR", 
    "category_c": "020200", 
    "category_1": null, 
    "category_2": null, 
    "category_3": null, 
    "address": "4 PAPANIKOLAOU GEORGIOU", 
    "street_nam": "ÐÁÐÁÍÉÊÏËÁÏÕ ÃÅÙÑÃÉÏÕ", 
    "number": "4", 
    "postcode": null, 
    "places_en_": "RODOS", 
    "f16": 1, 
    "f17": 0, 
    "tel": 2.2410974E9, 
    "fax": 0, 
    "mob": 0, 
    "email": null, 
    "url": null, 
    "places_gr": null, 
    "places_en": null 
    } 
}, 
{ 
    "type": "Feature", 
    "id": "rodos_business_pois.4", 
    "geometry": { 
    "type": "Point", 
    "coordinates": [ 
     28.226588152300117, 
     36.43403310824089 
    ] 
    }, 
    "geometry_name": "geom", 
    "properties": { 
    "id": null, 
    "business_p": "G-NET", 
    "name_owner": null, 
    "surname_ow": null, 
    "middle_nam": null, 
    "category_n": "RESTAURANT", 
    "category_c": "020100", 
    "category_1": null, 
    "category_2": null, 
    "category_3": null, 
    "address": "135 AGIAS ANASTASIAS", 
    "street_nam": "ÁÃÉÁÓ ÁÍÁÓÔÁÓÉÁÓ", 
    "number": "135", 
    "postcode": null, 
    "places_en_": "RODOS", 
    "f16": 1, 
    "f17": 0, 
    "tel": 2.2410351E9, 
    "fax": 0, 
    "mob": 0, 
    "email": null, 
    "url": null, 
    "places_gr": null, 
    "places_en": null 
    } 
}, 
{ 
    "type": "Feature", 
    "id": "rodos_business_pois.5", 
    "geometry": { 
    "type": "Point", 
    "coordinates": [ 
     28.215719877096184, 
     36.43079419827729 
    ] 
    }, 
    "geometry_name": "geom", 
    "properties": { 
    "id": null, 
    "business_p": "ANDRMEDA LOUNGE BAR", 
    "name_owner": null, 
    "surname_ow": null, 
    "middle_nam": null, 
    "category_n": "CAFE", 
    "category_c": "020100", 
    "category_1": null, 
    "category_2": null, 
    "category_3": null, 
    "address": "4 PAPANDREOU GEORGIOU", 
    "street_nam": "ÐÁÐÁÍÄÑÅÏÕ ÃÅÙÑÃÉÏÕ", 
    "number": "4", 
    "postcode": null, 
    "places_en_": "RODOS", 
    "f16": 1, 
    "f17": 0, 
    "tel": 2.2410974E9, 
    "fax": 2.2410975E9, 
    "mob": 0, 
    "email": null, 
    "url": null, 
    "places_gr": null, 
    "places_en": null 
    } 
}, 
{ 
    "type": "Feature", 
    "id": "rodos_business_pois.6", 
    "geometry": { 
    "type": "Point", 
    "coordinates": [ 
     28.226209613062103, 
     36.43806195312573 
    ] 
    }, 
    "geometry_name": "geom", 
    "properties": { 
    "id": null, 
    "business_p": "DOLCE CAFE", 
    "name_owner": null, 
    "surname_ow": null, 
    "middle_nam": null, 
    "category_n": "RESTAURANT", 
    "category_c": "020100", 
    "category_1": null, 
    "category_2": null, 
    "category_3": null, 
    "address": "14 DODEKANISIAKIS NEOLEAS", 
    "street_nam": "ÄÙÄÅÊÁÍÇÓÉÁÊÇÓ ÍÅÏËÁÉÁÓ", 
    "number": "14", 
    "postcode": null, 
    "places_en_": "RODOS", 
    "f16": 1, 
    "f17": 0, 
    "tel": 2.24102988E9, 
    "fax": 0, 
    "mob": 0, 
    "email": null, 
    "url": null, 
    "places_gr": null, 
    "places_en": null 
    } 
}, 
....... 
....... 
....... and so on.. 

我可以使用煎茶觸摸JSON讀者, 分析所有這些數據,以一定的時間,但現在我想解析這個數據按類別明智的意思是 在我想解析所有那些類別如BARCAFERESTAURANT的數據。

任何幫助將被appericiated。 在此先感謝。

+0

篩選下一次加載數據進店一定要仔細閱讀所有和過濾吧,否則讓你通過特定類別修改API,並相應獲得JSON – 1Mayur 2013-03-28 11:41:18

+0

你能提出一個很好的過濾器示例或關於如何修改API的建議嗎? – Tejas 2013-03-28 11:53:50

回答

1

這是你如何篩選店

store.filterBy(function(record, id){ 
    var cat = record.get('category_n'); 
    if(cat == 'BAR' || cat == 'CAFE' || cat == 'RESTAURANT'){ 
     return true; 
    }else{ 
     return false; 
    } 
}); 

這會遍歷每個記錄,並會將其在功能上,所以如果你想檢查category_n

編輯:請確保您清除店通過

store.clearFilter(); 
+0

謝謝..在記錄領域,我可以得到所有的數據,但卡在那裏,我不能繼續前進。 你能給我更多的解釋嗎? – Tejas 2013-03-29 04:55:39

+0

記錄將包含來自urjson數組的元素,並且它將一個接一個地迭代..從你的記錄匹配中你想要過濾的ccondition ..如果你返回true,那麼如果你返回false,那麼這個元素將在你的商店中可用,那麼它將會從商店中刪除... – 1Mayur 2013-03-29 05:36:05

+0

Console.log(cat);並看看它裏面有什麼...... – 1Mayur 2013-03-29 05:36:57