Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When in doubt, write down the structure of your JSON data. For example:</p> <pre><code>{ sethostname = ( { msgs = "Updating Apache configuration\nUpdating cPanel license...Done. Update succeeded.\nBuilding global cache for cpanel...Done"; status = 1; statusmsg = "Hostname Changed to: a.host.name.com"; warns = ( ); }); } </code></pre> <p>(which is in NeXTSTEP property list format, actually) means that you have a top-level dictionary. This top-level dictionary contains a key called <code>sethostname</code> whose value is an array. This array is comprised of dictionaries, each dictionary having a set of keys: <code>msgs, status, statusmsg, warns</code>. <code>msgs</code> has a string value, <code>status</code> has a number value, <code>statusmsg</code> has a string value<code>,</code>warns` has an array value:</p> <pre><code>dictionary (top-level) sethostname (array of dictionaries) dictionary (array element) msgs (string) status (number) statusmsg (string) warns (array) ??? (array element) </code></pre> <p>Having understood this structure, your code should look like:</p> <pre><code>NSError *myError = nil; NSDictionary *res = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&amp;myError]; if (!res) { // JSON parser failed } // dictionary (top-level) if (![res isKindOfClass:[NSDictionary class]]) { // JSON parser hasn't returned a dictionary } // sethostname (array of dictionaries) NSArray *setHostNames = [res objectForKey:@"sethostname"]; // dictionary (array element) for (NSDictionary *setHostName in setHostNames) { // status (number) NSNumber *status = [setHostName objectForKey:@"status"]; // statusmsg (string) NSString *statusmsg = [setHostName objectForKey:@"statusmsg"]; … } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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