Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to display the data from a HTTPResponse onto the user interface??

wolverinewolverine Posts: 181
edited August 2009 in iOS SDK Development
Inorder to a get the data from an external server, we can use an HTTP request,ie, change the URL in the way we want and sent it. But when the response comes, how can i collect the data and show it in my tableview ya labels instead of showing it as a webpage?
Post edited by wolverine on

Replies

  • sean119sean119 Posts: 5
    edited August 2009
    wolverine wrote: »
    Inorder to a get the data from an external server, we can use an HTTP request,ie, change the URL in the way we want and sent it. But when the response comes, how can i collect the data and show it in my tableview ya labels instead of showing it as a webpage?
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding] autorelease]
    
    ;
    I think you can display the "returnString" onto a view.
  • kelvinkaokelvinkao Posts: 352
    edited August 2009
    Well, you are going to be getting a chunk of data as a response to the HTTP request, and then you can do whatever you want with it. You can put it into an UIWebView to display it as a webpage, you can changed it into a string like the code in the post above, or you can parse it however you want. You are just getting back NSData. What you do with it is up to you.
    My dev blog:<br />
    <a href="http://www.kelvinkaodev.com"; target="_blank">http://www.kelvinkaodev.com</a>;
  • wolverinewolverine Posts: 181
    edited August 2009
    kelvinkao wrote: »
    Well, you are going to be getting a chunk of data as a response to the HTTP request, and then you can do whatever you want with it. You can put it into an UIWebView to display it as a webpage, you can changed it into a string like the code in the post above, or you can parse it however you want. You are just getting back NSData. What you do with it is up to you.

    Ya, i get that. I was trying to get data from a server related to stocks. But dont know how to get the specific values from this, was trying that. Do you have an idea?

    Thanks for the code sean.
  • kelvinkaokelvinkao Posts: 352
    edited August 2009
    What's the format of the response? XML?
    My dev blog:<br />
    <a href="http://www.kelvinkaodev.com"; target="_blank">http://www.kelvinkaodev.com</a>;
  • DutchDutch Posts: 884
    edited August 2009
    Generally something like this....
    NSString *returnedData=[[[NSString alloc] initWithData:myNSData encoding:NSASCIIStringEncoding] autorelease];
    

    That'll give you a string with the data that was sent. Then parse it and do what you want with it ...
  • wolverinewolverine Posts: 181
    edited August 2009
    kelvinkao wrote: »
    What's the format of the response? XML?

    When i printed it in a label, it was the whole page source code. Starting like
    <!DOCTYPE html PUBLIC " - //W3C..... and going on. This page source have all the db values written it, in the rows and columns. I was trying to get that values...

    I think I made it clear.:)
  • wolverinewolverine Posts: 181
    edited August 2009
    Dutch wrote: »
    Generally something like this....
    NSString *returnedData=[[[NSString alloc] initWithData:myNSData encoding:NSASCIIStringEncoding] autorelease];
    

    That'll give you a string with the data that was sent. Then parse it and do what you want with it ...

    Ya, upto there i was able to do it. After that i want to know how to parse and extract the values from it.
  • kelvinkaokelvinkao Posts: 352
    edited August 2009
    If it is XML, then there's the built-in NSXMLParser that you can use.

    If it is HTML, well, then you'll probably need to figure out how to parse it yourself. I saw some people recommend this but I don't know how good it is.
    Element Parser Touch Tank
    My dev blog:<br />
    <a href="http://www.kelvinkaodev.com"; target="_blank">http://www.kelvinkaodev.com</a>;
  • wolverinewolverine Posts: 181
    edited August 2009
    kelvinkao wrote: »
    If it is XML, then there's the built-in NSXMLParser that you can use.

    If it is HTML, well, then you'll probably need to figure out how to parse it yourself. I saw some people recommend this but I don't know how good it is.
    Element Parser Touch Tank

    Ya, its html only. I will check on that link u provided and will give the updates. Thanks for spending this much time for me. If i have any further doubts regarding the parsing, I will ask you. :)
  • wolverinewolverine Posts: 181
    edited August 2009
  • parismanparisman Posts: 2
    edited August 2009
    So how did ElementParser work for you?
Sign In or Register to comment.