javascript - Parsing JSON with jquery to get some value -
this json
{ "rajaongkir": { "query": { "origin": "23", "destination": "152", "weight": 1500, "courier": "all" }, "status": { "code": 200, "description": "ok" }, "origin_details": { "city_id": "23", "province_id": "9", "province": "jawa barat", "type": "kota", "city_name": "bandung", "postal_code": "40000" }, "destination_details": { "city_id": "152", "province_id": "6", "province": "dki jakarta", "type": "kota", "city_name": "jakarta pusat", "postal_code": "10000" }, "results": [ { "code": "pos", "name": "pos indonesia (pos)", "costs": [ { "service": "surat kilat khusus", "description": "surat kilat khusus", "cost": [ { "value": 16500, "etd": "2-4", "note": "" } ] }, { "service": "express next day", "description": "express next day", "cost": [ { "value": 22000, "etd": "1", "note": "" } ] } ] }, { "code": "jne", "name": "jalur nugraha ekakurir (jne)", "costs": [ { "service": "oke", "description": "ongkos kirim ekonomis", "cost": [ { "value": 18000, "etd": "2-3", "note": "" } ] }, { "service": "reg", "description": "layanan reguler", "cost": [ { "value": 20000, "etd": "1-2", "note": "" } ] }, { "service": "yes", "description": "yakin esok sampai", "cost": [ { "value": 30000, "etd": "1-1", "note": "" } ] } ] }, { "code": "tiki", "name": "citra van titipan kilat (tiki)", "costs": [ { "service": "sds", "description": "same day service", "cost": [ { "value": 135000, "etd": "", "note": "" } ] }, { "service": "hds", "description": "holiday delivery service", "cost": [ { "value": 49000, "etd": "", "note": "" } ] }, { "service": "ons", "description": "over night service", "cost": [ { "value": 26000, "etd": "", "note": "" } ] }, { "service": "reg", "description": "regular service", "cost": [ { "value": 17000, "etd": "", "note": "" } ] }, { "service": "eco", "description": "economi service", "cost": [ { "value": 14000, "etd": "", "note": "" } ] } ] } ] } } and problem how can "code" (inside of rajaongkir->result[]->code) ? try using jquery of value , append selectbox.
$.each(response['rajaongkir']['results']['code'], function(i,n){ cou = '<option value="'+n['code']+'">'+n['code']+'</option>'; cou = cou + ''; $(id).append(cou); }); but wrong in there.. wanna give selectbox 3 value json (pos,jne,tiki)
anyone can me please?
it looks trying iterate "results" array within json.
try removing ['code'] example:
$.each(response['rajaongkir']['results'], function(i,n){ ...
Comments
Post a Comment