Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON to NSDictionary to NSArray give me empty NSArray ? :(
    primarykey
    data
    text
    <p>Here is my problem :</p> <p>INPUT (from a certain website) :</p> <pre><code>{"error":[],"results":{"count":2,"data":[{"ART_ID":"656","ART_NAME":"Noir D\u00e9sir","ART_PICTURE":".....","NB_ALBUM":"15","NB_FAN":"90176","SMARTRADIO":"1","URL_REWRITING":"noir-desir"},{"ART_ID":"167225","ART_NAME":"LMFAO","ART_PICTURE":"....","NB_ALBUM":"17","NB_FAN":"122408","SMARTRADIO":"1","URL_REWRITING":"lmfao"}],"total":2}} </code></pre> <p>So, once I have that I'm using a few JSON classes :</p> <pre><code> NSError* jsonError = nil; //responseData contains my json feed NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&amp;jsonError]; NSLog(@"responseDictionary : \n%@\n--------\n", [dict description]); </code></pre> <p>In order to obtain the following :</p> <pre><code>{ error = ( ); results = { count = 2; data = ( { "ART_ID" = 656; "ART_NAME" = "Noir D\U00e9sir"; "ART_PICTURE" = 17b0a9c3defcf8c3eef943759606b3f4; "NB_ALBUM" = 15; "NB_FAN" = 90176; SMARTRADIO = 1; "URL_REWRITING" = "noir-desir"; }, { "ART_ID" = 167225; "ART_NAME" = LMFAO; "ART_PICTURE" = 72a09b9202da38afae077e80c7598212; "NB_ALBUM" = 17; "NB_FAN" = 122408; SMARTRADIO = 1; "URL_REWRITING" = lmfao; } ); total = 2; }; } </code></pre> <p>Here, I don't really have any problem... But now, I want to get the "data" field in this NSDictionary. So I just create a new one :</p> <pre><code>NSDictionary* resultField = [NSDictionary dictionaryWithDictionary:[dict objectForKey:@"results"]]; </code></pre> <p>Wich contains :</p> <pre><code>{ count = 2; data = ( { "ART_ID" = 656; "ART_NAME" = "Noir D\U00e9sir"; "ART_PICTURE" = 17b0a9c3defcf8c3eef943759606b3f4; "NB_ALBUM" = 15; "NB_FAN" = 90176; SMARTRADIO = 1; "URL_REWRITING" = "noir-desir"; }, { "ART_ID" = 167225; "ART_NAME" = LMFAO; "ART_PICTURE" = 72a09b9202da38afae077e80c7598212; "NB_ALBUM" = 17; "NB_FAN" = 122408; SMARTRADIO = 1; "URL_REWRITING" = lmfao; } ); total = 2; } </code></pre> <p>Now I want to get my "data" field, which now is a JSONArray (not a NSDictionary anymore...) :</p> <pre><code>NSArray* dataField = [[NSArray alloc] initWithArray:[dict objectForKey:@"data"]]; </code></pre> <p>But after that my dataField is empty... By that I mean this :</p> <pre><code>NSArray* dataField = [[NSArray alloc] initWithArray:[dict objectForKey:@"data"]]; if (!dataField || ![dataField isKindOfClass:[NSArray class]]) { NSLog(@"Pb parsing DATA field as NSArray..."); } NSLog(@"dataField : \n%@\n--------\n", [dataField description]); </code></pre> <p>Doesn't show me the error since it a correctly formatted NSArray, but prints me the following :</p> <pre><code>2012-02-02 14:08:52.315 myapp[5235:f803] dataField : ( ) </code></pre> <p>I now am lost, I really don't know what's happening... If you guys have any clue on this issue I'd be glad if you could help me !</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload