php - Parsing JSON when multiple arrays returned in Objective C -


i trying parse json returned following link:

https://icansolvecouk1.fatcow.com/prco303/loginjson.php?nickname=maggie&password=maggie

which is:

[{"sent":"2013-05-12 09:32:14","sender":"1","recipient":"1","message":"hey hey hey"},{"sent":"2013-05-12 16:39:02","sender":"2","recipient":"1","message":"another message"}] 

using following code in obj-c:

nsdictionary *user = [result json]; nslog(@"nsdictionary returned: %@",user); nsarray* arrayofreturneditems = [user objectforkey:@"message"]; nslog(@"array returned: %@",[arrayofreturneditems objectatindex:0]); 

nsdictionary stores json value errors occur later on. new obj-c , json appreciated. checked on jsonlint.com says valid believe reason errors getting pulling 2 arrays (from url) not parsing correctly. have access server serving json perhaps need make change there?

spent half day searching site before went ahead , asked i'll result!

thanks

error xcode:

2013-05-12 23:37:20.096 securecomms[27240:1307] -[__nsarraym objectforkey:]: unrecognized selector sent instance 0x8957e30 2013-05-12 23:37:20.097 securecomms[27240:1307] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarraym objectforkey:]: unrecognized selector sent instance 0x8957e30' * first throw call stack: (0x1c98012 0x10d5e7e 0x1d234bd 0x1c87bbc 0x1c8794e 0x47dc 0x4399 0xbd8cf8 0xb4075a 0xb0e453 0xb0e164 0xb9aa31 0x49fc53f 0x4a0e014 0x49ff2e8 0x49ff450 0x91758e72 0x91740d2a) libc++abi.dylib: terminate called throwing exception

this line:

nsdictionary *user = [result json]; 

should be:

nsarray *users = [result json]; 

then need process each of (or 1 of) dictionaries in array.

next, message you're trying extract string (nsstring), you're code says array you'll have problems there too.

you may find useful log class of items check think things are:

nslog(@"class or user:%@", nsstringfromclass(user)); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -