xcode - String problems after NSUTF8StringEncoding -
i try download json string server, doesn't way should. sorry formatting, first time using stackoverflow..
as can see in comparison received string , var_dump php, key's arr[listing][<this ones>] removed.. , further json decoding treat entry arr[listing][<this one>] 1 value, instead of array sub-dimension
any ideas?
what tried:
nsdata *serverres = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nsstring *serverres_str=[[nsstring alloc]initwithdata:serverres encoding:nsutf8stringencoding]; nslog(@"%@",serverres_str); what looks like:
{"status":{"result":"ok","code":205,"info":"get_projects","authenticated":1,"userid":1,"access":1000,"system_name":"testdatei","ssl":false,"identifier":""},"content":{"get_projects":{"count":7,"listing":[{"id":"1","name":"devel","creation_date":"1357116685","created_by":"admin","type":"project","public":false,"privat":false,"access":3,"thumbnail":""},{"id":"30","name":"p5","creation_date":"1365866791","created_by":"admin","type":"project","public":false,"privat":false,"access":3,"thumbnail":""},{"id":"29","name":"p4","creation_date":"1365866785","created_by":"admin","type":"project","public":false,"privat":false,"access":3,"thumbnail":""},{"id":"28","name":"p3","creation_date":"1365866780","created_by":"admin","type":"project","public":false,"privat":false,"access":3,"thumbnail":""},{"id":"27","name":"p2","creation_date":"1365866773","created_by":"admin","type":"project","public":false,"privat":false,"access":3,"thumbnail":""},{"id":"26","name":"p1","creation_date":"1365866767","created_by":"admin","type":"project","public":false,"privat":false,"access":3,"thumbnail":""},{"id":"4","name":"testimmortals","creation_date":"1362388820","created_by":"admin","type":"project","public":false,"privat":false,"access":3,"thumbnail":""}]}}} what should like:
array(2) { ["count"]=> int(7) ["listing"]=> array(7) { [0]=> array(9) { ["id"]=> string(1) "1" ["name"]=> string(5) "devel" ["creation_date"]=> string(10) "1357116685" ["created_by"]=> string(5) "admin" ["type"]=> string(7) "project" ["public"]=> bool(false) ["privat"]=> bool(false) ["access"]=> int(3) ["thumbnail"]=> string(92) "" } [1]=> array(9) { ["id"]=> string(2) "30" ["name"]=> string(2) "p5" ["creation_date"]=> string(10) "1365866791" ["created_by"]=> string(5) "admin" ["type"]=> string(7) "project" ["public"]=> bool(false) ["privat"]=> bool(false) ["access"]=> int(3) ["thumbnail"]=> string(93) "" } [2]=> array(9) { ["id"]=> string(2) "29" ["name"]=> string(2) "p4" ["creation_date"]=> string(10) "1365866785" ["created_by"]=> string(5) "admin" ["type"]=> string(7) "project" ["public"]=> bool(false) ["privat"]=> bool(false) ["access"]=> int(3) ["thumbnail"]=> string(93) "" } [3]=> array(9) { ["id"]=> string(2) "28" ["name"]=> string(2) "p3" ["creation_date"]=> string(10) "1365866780" ["created_by"]=> string(5) "admin" ["type"]=> string(7) "project" ["public"]=> bool(false) ["privat"]=> bool(false) ["access"]=> int(3) ["thumbnail"]=> string(93) "" } [4]=> array(9) { ["id"]=> string(2) "27" ["name"]=> string(2) "p2" ["creation_date"]=> string(10) "1365866773" ["created_by"]=> string(5) "admin" ["type"]=> string(7) "project" ["public"]=> bool(false) ["privat"]=> bool(false) ["access"]=> int(3) ["thumbnail"]=> string(93) "" } [5]=> array(9) { ["id"]=> string(2) "26" ["name"]=> string(2) "p1" ["creation_date"]=> string(10) "1365866767" ["created_by"]=> string(5) "admin" ["type"]=> string(7) "project" ["public"]=> bool(false) ["privat"]=> bool(false) ["access"]=> int(3) ["thumbnail"]=> string(93) "" } [6]=> array(9) { ["id"]=> string(1) "4" ["name"]=> string(13) "testimmortals" ["creation_date"]=> string(10) "1362388820" ["created_by"]=> string(5) "admin" ["type"]=> string(7) "project" ["public"]=> bool(false) ["privat"]=> bool(false) ["access"]=> int(3) ["thumbnail"]=> string(92) "" } } }
have tried json library comes ios ? has handy method :
nsarray *responsevalues = [responsestring jsonvalue]; or
nsdictionary *responsevalues = [responsestring jsonvalue]; - you can array or dictionary whatever, because
jsonvaluemethod returnsid, can adapt whatever you're receiving.
you can find library here: https://github.com/stig/json-framework
hope helps.
Comments
Post a Comment