0

sorry for my bad English. I've managed how to get authorization token from this question And now I can't get how to work with XML. The documentation says (translating):
get contents of /me/ resource:
https://api-yaru.yandex.ru/me/?oauth_token=111111111111111111

The answer will be in XML format
Please, explain, how can I get this XML file to parse it? Do I need to use AsyncTask?
The "dirty" code is here: http://pastebin.com/NjTiUpC5

1 Answer 1

1

you need to simply append '&format=json' into your url to get response in json format

https://api-yaru.yandex.ru/me/?oauth_token=111111111111111111&format=json

in your case

HttpEntity entity = resp.getEntity();
String jsonStr = EntityUtils.toString(entity);
JSONObject jsonObj = new JSONObject(jsonStr);

and for get xml string

String xml = EntityUtils.toString(resp.getEntity());

if you want to simply print it

and do what ever you want. good luck ;)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but that's not the question. The question is about "how to be able to work with xml file with GET request?"
Sorry but part of your original message was "Please, explain, how can I get this XML file (or JSON, what's better?) to parse it?". If you still think about json see this link stackoverflow.com/a/9606629/1326308
if you still want to use xml read docs developer.android.com/training/basics/network-ops/xml.html

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.