0

Possible Duplicate:
Iterating through NSDictionary for null value

I have a json like image, i want to replace all value string to an empty string. I see that it is similar to this question but all the value have not changed.

Community
  • 1
  • 1
heaven
  • 221
  • 4
  • 19

2 Answers2

2

Your "<null>" is not a null! This is a NSString. If you want null in your JSON you should have

"someKey": null

If you want to repleace it you should use NSNull class

EDIT:

Based on screenshots in comments: If you using this category to your Dictionary from SBJSON this is very wrong. You assume that everything you received from JSON is NSString which is not true. If you don't and using it for every sub-dictionaty this is ok.

Change

if(object == nul)

to

if([object isKindOfClass:[NSNull class]])

or in your JSON (this is really REALLY wrong!)

if([object isKindOfClass:[NSString class]])
   if([(NSString*)object isEqualToString:@"<null>"])

And please edit your original post with code. Not pase a screenshots in comments.

Jakub
  • 13,712
  • 17
  • 82
  • 139
  • I use code like link here http://stackoverflow.com/questions/12213822/replace-occurance-of-nsnull-in-nested-nsdictionary --> but value null don't replace, and i have no idea – heaven Dec 14 '12 at 11:13
  • Which part of code? where? I can help you if you don't post your code and sample JSON. – Jakub Dec 14 '12 at 18:17
  • Sample Json -> http://mocku.ps/wz69f, and my code is ->http://mocku.ps/m41e1h – heaven Dec 14 '12 at 20:28
  • I've edit my original answer. – Jakub Dec 14 '12 at 20:43
  • I've used to dispatch_asycn to get json from to service, and it has value null string, exactly i see the string is when i put nslog.In my question i'm going to write code to clear, but when the json code it breaks font should I put on the visual image, thank you for your words comments – heaven Dec 14 '12 at 21:18
0

you can do this by using enumerateKeysAndObjectsUsingBlock:. Here is the solution you are trying, check this link.

Community
  • 1
  • 1
arthankamal
  • 6,341
  • 4
  • 36
  • 51
  • thank @arthan.v, i have seen link, the code doesn't work, and i still not yet replace all the value null in json – heaven Dec 14 '12 at 11:15