0

I was wondering if I can use JavaScript with Objective-C to parse data.
I saw examples of getting NSMutableData from a web server.

I was wondering if I could then use JavaScript methods for parsing the data in the DOM tree (ie getElementById).

Macmade
  • 50,827
  • 12
  • 106
  • 123
Crystal
  • 27,012
  • 59
  • 215
  • 378

1 Answers1

0

I'm not entirely sure what you mean, but you can definitely use JavaScript with Objective-C. On iOS, you could put the NSData that you got from a server into a UIWebView with the loadData:MIMEType:textEncodingName:baseURL: method. Then you can use stringByEvaluatingJavaScriptFromString: to run any JavaScript on the stuff you put into the web view.

There's a second option. You could use JavaScriptCore directly, but I don't think that's what you're looking for: Embed a JavaScript engine in an iOS application

Community
  • 1
  • 1
Johannes Fahrenkrug
  • 40,544
  • 18
  • 119
  • 159
  • Yeah I was trying to see if I could get the data from the web server (like view source), search for certain tags using Javascript, like getElementById.value, and then show my values in a nice UITableView or something like that. – Crystal Dec 02 '11 at 16:07