smallseo.info

JSONKit

Objective-C JSON

Can't turn off ARC for JSONkit

Using JSONkit for a project that is ARC enabled, and having issues. I flagged the files appropriately as -fno-objc-arc and tried a build, but it is still throwing errors like ARC is enabled. Any ideas what I could be missing?

For clarity, I flagged the file in Build Phases->Compile Sources->JSONkit.m

EDIT: screen shot of the errors. These are the same errors I got before adding the flag for the file to be ignored by ARC enter image description here


Source: (StackOverflow)

Nimbus framework, using CocoaPods, with the Xcode 5 and iOS 7 SDK

Endless issues here:

  1. Nimbus itself is bloated and less maintained every day
  2. I feel, I am forced to upgrade Nimbus from 0.9.3 to 1.0.0 for various reasons
  3. Upgrading Nimbus from 0.9.3 to 1.0.0 has lots of changes (e.g., AFNetworking)
  4. Latest podspec depends on JSONKit, which won't build out–of–the–box, because of ARC/deprecation issues

Anyone could/did manage to build with Xcode 5 and iOS 7 SDK for, at least, iOS 7 target?


Source: (StackOverflow)

Is NSJSONSerialization more error-tolerant and robust than JSONKit?

Although according to benchmarks JSONKit is faster, the Github readme is full of warnings that illformed JSON leads to crashes, etc.

For me it is more important that there is no crash, and that an ilformed Unicode JSON or other subtle error in the JSON file does not cause a crash.

Maybe the speed increase comes from it's strictness and unforgivingness towards errors? Is NSJSONSerialization more robust in this regard?


Source: (StackOverflow)

Is JSONKit creating memory leaks?

I have been using JSONKit in my app, but now that I have upgraded to Xcode 4.5.1 and run the analyze, Xcode is reporting possible memory leaks in JSONKit code.

/Users/aleksa.topic/SVN/Apple/iTTChart/trunk/iTTChart/Other Sources/JSONKit.m:682:23: Memory is never released; potential leak of memory pointed to by 'array' (and the it gives the same potential leak for dictionary).

Does anyone have some experience with this? Is it really creating memory leaks or is it just that Xcode is't analyzing good enough?


Source: (StackOverflow)

Which json library to use on iphone to consume gson/jackson generated json

I need to build a java based JSON data API that will be accessed from mobile devices: Android, Iphone... I have narrowed down to these:

  • Server side data api - gson/jackson lib (pojo to json)
  • Android side - gson/jackson lib (json to pojo)
  • Iphone side - I googled & found that there are a bunch of frameworks Jsonkit, json-framework, touch json etc etc.

Question:

  • Can someone make a recommendation on the iphone side json library? The gson/jackson generated json output of the data api, must be consumable from iphone without any special tweaks to json structure

  • Is there any java Collection type that I should stay away from(on server side) to ensure the json is directly convertible to objective c objects?

  • Any other gotchas?

Note: I am aware of PhoneGap, titanuim & some equivalents - but not interested in them. Json is meant to be a universal format, but I have had cross-library issues earlier - hence this attempt to understand from people with prior experiance on the subject

Thanks!


Source: (StackOverflow)

iOS: Serialize/Deserialize complex JSON generically from NSObject class

Anyone have idea how to serialize nested JSON based on NSObject class? There is a discussion to serialize simple JSON here , but it is not generic enough to cater complex nested JSON.

Imagine this is the result of JSON:

{ "accounting" : [{ "firstName" : "John",  
                    "lastName"  : "Doe",
                    "age"       : 23 },

                  { "firstName" : "Mary",  
                    "lastName"  : "Smith",
                    "age"       : 32 }
                              ],                            
  "sales"      : [{ "firstName" : "Sally", 
                    "lastName"  : "Green",
                    "age"       : 27 },

                  { "firstName" : "Jim",   
                    "lastName"  : "Galley",
                    "age"       : 41 }
                  ]}

From this class:

@interface Person : NSObject{}
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, strong) NSNumber *age;
@end

@interface Department : NSObject{}
@property (nonatomic, strong) NSMutableArray *accounting; //contain Person class
@property (nonatomic, strong) NSMutableArray *sales; //contain Person class
@end

How to serialize/deserialize them based on class generically?

EDIT

Currently i'm able to generate payload like this based on any class:

NSMutableDictionary *Payload = [self serialize:objClass];

But it does not cater nested complex JSON. Anyone have better solution for this? This library for C# cater serialize/deserialze based on object class. I want to reproduce something the same based on NSObject


Source: (StackOverflow)

Parsing JSON Array in iOS with JSONKit - array with no tag for ObjectForKey?

I am trying to parse a JSON array returned by a RESTful web API that looks similiar to the following (using JSONKit):

[ { "DateCreated" : "/Date(1320296400000)/",
    "ID" : 1,
    "Summary" : "Summary 1",
    "Title" : "Title 1",
    "URL" : "URL 1"
  },
  { "DateCreated" : "/Date(1320296400000)/",
    "ID" : 2,
    "Summary" : "Summary 2",
    "Title" : "Title 2",
    "URL" : "URL 2"
  }
]

The JSON I have worked with the the past usually had a parent element, for example news:{{node1},{node2}}, that would allow me to extract that node from the JSON response, like this:

NSString *response = [request responseString];
NSDictionary *deserializedData = [response objectFromJSONString];
NSArray *arrNews = [deserializedData objectForKey:@"news"];

In my JSON, no such node exists, it is simply a raw array. How do I go about pulling this into an NSArray (or something I can hook into a UITableView)?


Source: (StackOverflow)

How do I JSON serialize an NSDate Dictionary in JSONKit

I tried this using Jsonkit and Apple's JSON serializer with no luck. It keeps breaking on the geo property, which is an nsarray of NSNumbers.

Post* p = [[Post alloc] init];

    p.uname = @"mike";
    p.likes =[NSNumber numberWithInt:1];
    p.geo = [[NSArray alloc] initWithObjects:[NSNumber numberWithFloat:37.78583], [NSNumber numberWithFloat:-122.406417], nil ];
    p.place = @"New York City";
    p.caption = @"A test caption";
    p.date = [NSDate date];


 NSError* error = nil;

    NSString* stuff = [[p getDictionary] JSONStringWithOptions:JKParseOptionNone error:&error];

UPDATE: Checking on the error it's the NSDate that it fails on, not the NSArray. How do I pass in the date formatter into the function?

UPDATE 2: Solved- ok looked at the latest commit for jsonkit and saw that you could do this:

 NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"];

    NSString* result = [p.dictionary JSONStringWithOptions:JKSerializeOptionNone serializeUnsupportedClassesUsingBlock:^id(id object) {
        if([object isKindOfClass:[NSDate class]]) { return([outputFormatter stringFromDate:object]); }
        return(nil);
    } error:nil];

which seems to have worked but note that this feature for JSONKit is WIP so it could change in the next official release.


Source: (StackOverflow)

is there an example of AFHTTPClient posting json with AFNetworking?

Looking for an example of how to post json with AFHTTPClient. I see that there is a postPath method which takes an NSDictionary and the AFJSONEncode method returns an NSData. Is there an easy way to serialize an object to NSDictionary, or is there an easier way using jsonkit?

I just need to post the object as json to a REST API.

UPDATE: So I tried passing a dictionary over but it seems to break on serializing a nested array.

For example, if I have an object:

Post* p = [[Post alloc] init];
p.uname = @"mike";
p.likes =[NSNumber numberWithInt:1];
p.geo = [[NSArray alloc] initWithObjects:[NSNumber numberWithFloat:37.78583], [NSNumber numberWithFloat:-122.406417], nil ];
p.place = @"New York City";
p.caption = @"A test caption";
p.date = [NSDate date];

who's get dictionary has data like the following:

{
    caption = "A test caption";
    date = "2011-12-13 17:58:37 +0000";
    geo =     (
        "37.78583",
        "-122.4064"
    );
    likes = 1;
    place = "New York City";

}

the serialization will either just fail outright or geo will not be serialized as an array but as a string literal like ("37.78583", "-122.4064");


Source: (StackOverflow)

JSONKit benchmarks

I pulled the code from http://www.bonto.ch/blog/2011/12/08/json-libraries-for-ios-comparison-updated/ and tested it on my local machine.

I was surprised by the results and NSJSonSerialization gave much better performance than JSONKit.

Has NSJSonSerialization really overtaken JSONKit in terms of speed or did I do something wrong?

twitter_timeline_json.png

twitter_timeline.json

repeat_json.png

repeat.json

random_json.png

random.json


Source: (StackOverflow)

iOS 7 : 'isa' is deprecated

I get warning when I run my app in iOS7 "'isa' is deprecated", I don't have any idea how to fix this warning message. Please any one help on this.

array->isa      = _JKArrayClass;

Source: (StackOverflow)

Does JSONKit support ARC, or is there a fork that supports ARC?

According to these comments, JSONKit does not support ARC, and not even running with fobjc-no-arc setting in an ARC environment: https://github.com/johnezang/JSONKit/issues/37


Source: (StackOverflow)

JSONKit: changing and serializing JSON attribute's value

I am using JSONKit to parse JSON string into NSDictionary:

NSDictionary *deserializedData = [jsonString objectFromJSONString];

My question is: how can I change the dictionary values and get a changed JSON String?

I've tried to change the dictionary values:

[deserializedData setObject:[NSNumber numberWithInt:iRatings] forKey:@"ratings"];   

But the app crashes in that line. What am I doing wrong?

Thanks in advance!


Source: (StackOverflow)

JSONKit unrecognized selector while serializing

I am trying to use the JSONKit library and have included the source files in my project. I have included the JSONKit.h header so that the included category gives NSDictionary objects the JSONData and JSONString selectors.

  NSMutableDictionary* root = [NSMutableDictionary dictionary];
  [root setValue:@"CONNECT" forKey:@"command"];
  NSData* data = [root JSONData];

But at runtime I get the following error:

 -[__NSCFDictionary JSONString]: unrecognized selector sent to instance 0x784b870

Why is the category not adding the appropriate methods to NSDictionary objects?


Source: (StackOverflow)

Errors on JSONKit implement

The Errors

Upon importing the JSONKit.h and JSONKit.m files into my project , i get the following errors. I have browsed and browsed but none seems to have encountered these problems ?

All i did was import the files and build and then i get this

Is it something i forgot to import or ...??????


Source: (StackOverflow)