arrays - Filter SwiftyJson Data -


i have json data. array of dictionaries swiftyjson array called jsonobj["customer"] , looks like:

[{     "kode_customer": 1,     "nama_customer": "logam jaya, ud",     "alamat_customer": "rajawali no 95",     "kodepos": 60176,     "kode_provinsi": 11,     "gps_lat": -7.233834999999999,     "gps_long": 112.72964666666667 }, {     "kode_customer": 2,     "nama_customer": "terang, tk",     "alamat_customer": "raya dukuh kupang 100",     "kodepos": 60225,     "kode_provinsi": 11,     "gps_lat": -7.285430000000001,     "gps_long": 112.71538333333335 }, {     "kode_customer": 3,     "nama_customer": "sinar family",     "alamat_customer": "by pass jomin no 295",     "kodepos": 41374,     "kode_provinsi": 9,     "gps_lat": -6.4220273,     "gps_long": 107.4748978 }, {     "kode_customer": 4,     "nama_customer": "lancar laksana, tb",     "alamat_customer": "jendral sudirman no 69",     "kodepos": 41374,     "kode_provinsi": 9,     "gps_lat": -6.4220273,     "gps_long": 107.4748978 }] 

now want fo filter data in way

let filterddata = self.jsonobj["customer"].filter({(json) -> bool in return self.jsonobj["customer"]["kodepos"] < 6000 }) 

i want see 2 results. not work, think because of missing 'index' between

self.jsonobj["customer"] , ["kodepos"] 

or let me in way

print (self.jsonobj["customer"]["kodepos"]) ...i want see values kodepos

how possible filter data in swiftyjson.

one approach use .arrayvalue of swiftyjson object create filter

let customers = self.jsonobj["customer"].arrayvalue let filterddata = customers.filter(){     item = $0     return item["customer"]["kodepos"].intvalue < 6000     } 

refer subscript section in swiftyjson repository https://github.com/swiftyjson/swiftyjson#subscript


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -