5

I have a PHP page which echos some JSON like so:

echo json_encode("Hello");

How can I access this in my swift app? I used a method to get data from the website before, when I println the data returned, it just prints all of the HTML code for the website (including tags).

    let url = NSURL(string: myLinkUrl)
    let request = NSURLRequest(URL: url!)

    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in
        println(NSString(data: data, encoding: NSASCIIStringEncoding)) //Prints HTML code
    }

I would like to know how to only print the data that the page echos (in this case 'Hello')

2

1 Answer 1

0

Please make sure that you are printing just the json data in your php page. There should not be any html tags. The json should be in key-value pairs so that you can access it easily. A sample php file to generate valid json is given below.

<?php
 $response['data']="Hello";
 echo json_encode("Hello");
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.