1

I am trying to get all arrays I store in: https://s3.eu-west-2.amazonaws.com/tekstpieprz/strings.xml

I would like to use them for my textviews. I have added Unirest but cannot get my head around JSON. I have tried to play with something like:

HttpResponse<JsonNode> request = (HttpResponse<JsonNode>) Unirest.get("https://s3.eu-west-2.amazonaws.com/tekstpieprz/strings.xml")
            .getBody("docukrz");
    JSONObject myObj = request.getBody().getObject();
    final JSONArray results  = myObj.getJSONArray(String docukrz);

so then I can use the array in:

    final String[] docukrz = res.getStringArray(R.array.docukrz);

But instead using

Resources

I would like to use the array I store online. I do not fully understand how JSON works, I have only started learning JAVA 6 weeks ago. Any help would be much much appreciated.

4
  • 1
    The response is in XML, not JSON. You need to use an XML parser. Commented Nov 17, 2018 at 15:11
  • But how? Honestly wherever I ask I cannot find a simple answer. I have searched a lot on stack and other forums and everyone is suggesting something else. I have been suggested to use Unirest, retrofit, xml parse. I am just learning this stuff and I honestly don't know where to learn from. I may as well just keep the resources file locally, but I thought I will go step forward and put it online, so I can change it whenever I want without new app version. Would appreciate some more details or at least to point where I could begin or where to learn from. Thanks! Commented Nov 17, 2018 at 15:20
  • Online resources are a bad idea. What if the device is offline? Commented Nov 17, 2018 at 15:23
  • Then it won't work, simple as that. I will be updating the file frequently plus I have spent so much time on it I would like to know how to do that for future. Sorry but your comment does not help. Commented Nov 17, 2018 at 15:27

1 Answer 1

1

You can find XML prase example here How can I parse xml from url in android?. according to that answer, your code should be like below

   URL url = new URL("https://s3.eu-west-2.amazonaws.com/tekstpieprz/strings.xml");
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     DocumentBuilder db = dbf.newDocumentBuilder();
     Document doc = db.parse(new InputSource(url.openStream()));
     doc.getDocumentElement().normalize();

     NodeList nodeList = doc.getElementsByTagName("docukrz");
     ArrayList resourceList = new ArrayList();
      for (int i = 0; i < nodeList.getLength(); i++) {

          Node node = nodeList.item(i);
          resourceList.add(node);
 }
Sign up to request clarification or add additional context in comments.

1 Comment

If another question has the same answer, you should mark as duplicate, not copy the answer.

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.