Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:51:16+00:00 2026-05-24T09:51:16+00:00

How do I parse an HTML response in Objective-C, to find a JSON object

  • 0

How do I parse an HTML response in Objective-C, to find a JSON object embedded in the HTML.

here is the response I’m getting…

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><title>
<script src="/Scripts/LocalLogin_vv1CC4D69C143F4D6.js" type="text/javascript"></script>
<script type="text/javascript">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv=X-UA-Compatible content=IE=EmulateIE7 />
<title></title>

<script type="text/javascript" language="javascript">


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.\<br /\>Please click {0} now.',
    notConnected: 'You have been disconnected.\<br /\>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);
}
});
</script>
</head>
</body>
</html>

Now, how in the world do I get a hold of the:

enrollments: [{id: '2366888', userId: '2269113'}]

and make it a json object so I can retrieve the userId?

PS: I already have the response stored in a NSString object….

Thanks in advance!!!


So, I tried the following:

NSString* regexString =@"enrollments: \[.*?\],";
NSRegularExpressionOptions options = NSRegularExpressionCaseInsensitive;
NSError* regExerror = NULL;

NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:regexString options:options error:&regExerror];
if (regExerror) {
    NSLog(@"%@", [regExerror description]);
}

    //store the response from the server - HTML FORMAT
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&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);
}

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…

Any ideas? THANKS!!! 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:51:17+00:00Added an answer on May 24, 2026 at 9:51 am

    If you’re not targeting iOS4+, you can use NSScanner. Depending on how reliably that page is rendered, you could use something like

    NSScanner* scanner = [NSScanner scannerWithString:yourStringHere];
    NSString* targetString; //your JSON ends up here
    [scanner scanUpToString:@"enrollments: " intoString:NULL];
    [scanner scanUpToString:@"\n" intoString:&targetString];
    

    However, if you’re okay with targeting iOS4+, I’d strongly agree with j0k that NSRegularExpression is the way to go. If you’re not familiar with regular expressions, the pattern I’d suggest is something like @"enrollments: \[.*?\]," to match the whole string, or if it’s super reliably looking like that (ie, always an array with one object with those exact properties, you could try @"enrollments: [{id: '(\d+?)', userId: '(\d+?)'}]".

    On the other hand, the first one is more flexible and you can easily use something like Nextive JSON to parse it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to find away to parse html and css layout to be able
I am trying to parse a response data as html format. The data contains
I'm getting this error with following line: Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(html.toString()))); Details:
I am getting json data as a response back from the server. I want
I have a Html Response for my application that I need to parse ultimately.
1) Does HtmlUnit parse HTML before getting an element (by sth. like HtmlWebPage.getElementBy... )?
Is there a library to parse a HTML response in in C++ .net?
is it possible to request a url and parse the html response in nodejs
I need to parse html for a project and looking for a good html
My goal is to parse HTML with lxml, which supports both XPath and CSS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.