Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I parse an HTML response in Objective-C?
    primarykey
    data
    text
    <p>How do I parse an HTML response in Objective-C, to find a JSON object embedded in the HTML.</p> <p>here is the response I'm getting...</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head id="Head1"&gt;&lt;title&gt; &lt;script src="/Scripts/LocalLogin_vv1CC4D69C143F4D6.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head&gt; &lt;meta http-equiv=X-UA-Compatible content=IE=EmulateIE7 /&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript" language="javascript"&gt; FRAME_API = new FrameApi({ userId: '2269113', proxyUserId: '2269113', isProxy: false, username: 'inst1', enrollments: [{id: '2366888', userId: '2269113'}], viewAda: false, // Strings I18N : { ItemViewerFrame: 'Item Viewer Frame', ItemEditorFrame: 'Item Editor Frame', GroupSetupFrame: 'Group Setup Frame', notLoggedIn: 'You are no longer logged in.\&lt;br /\&gt;Please click {0} now.', notConnected: 'You have been disconnected.\&lt;br /\&gt;Please connect and click {0}.', login: 'Login' } }); Ext.onReady(function() { if (typeof (Ext.QuickTips) != 'undefined') { Ext.QuickTips.init(); } var parentApi = FRAME_API.findParentApi(window); if(parentApi != null) { FRAME_API = parentApi; } else { FRAME_API.init(15); } }); &lt;/script&gt; &lt;/head&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Now, how in the world do I get a hold of the:</p> <pre><code>enrollments: [{id: '2366888', userId: '2269113'}] </code></pre> <p>and make it a json object so I can retrieve the userId?</p> <p>PS: I already have the response stored in a NSString object....</p> <p>Thanks in advance!!!</p> <hr> <p>So, I tried the following:</p> <pre><code>NSString* regexString =@"enrollments: \[.*?\],"; NSRegularExpressionOptions options = NSRegularExpressionCaseInsensitive; NSError* regExerror = NULL; NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:regexString options:options error:&amp;regExerror]; if (regExerror) { NSLog(@"%@", [regExerror description]); } //store the response from the server - HTML FORMAT NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; NSString* loginResponse = [[[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding] autorelease]; NSArray* results = [regex matchesInString:loginResponse options:0 range:NSMakeRange(0, [loginResponse length])]; for (NSTextCheckingResult* result in results) { NSString* resultString = [loginResponse substringWithRange:result.range]; NSLog(@"%@",resultString); } </code></pre> <p>But nothing gets store in the a array... I tested the regex at a few online testers with different portions of the response and it works fine... this is my first time using regex in general. I already looked in the class reference and it seems like it "SHOULD" work...</p> <p>Any ideas? THANKS!!! :D</p>
    singulars
    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.
 

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