top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to analyse Json data from Url (JSON-API)?

+1 vote
544 views

Please help me with following -
1. Write a java program to get json data from URL http://echo.jsontest.com/Operand1/10/Operand2/5/Operator/+
2. Perform mathematical operation in java after reading JSON from above URL and print result.for ex.result=10+5=15
3. Result should be dynamic and should change if change values in above URL.

posted Feb 5, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Will it solve by printing on consol or some other method.?please anyone can help me out..

1 Answer

0 votes

This link is not working, anyway I got the problem and providing the steps
1.Read the URL and get the JSON string something like

  public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
    InputStream is = new URL(url).openStream();
    try {
      BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
      String jsonText = readAll(rd);
      JSONObject json = new JSONObject(jsonText);
      return json;
    } finally {
      is.close();
    }
  }

2.Decode the JSON string something like

JSONObject json = readJsonFromUrl("<Your URL>");
System.out.println(json.get("opr1"));
System.out.println(json.get("opr2"));
System.out.println(json.get("operator"));

3.Rest is simple and leave it to you how you would solve it, just need to use opr1, opr2 and operator :)

answer Feb 5, 2016 by Salil Agrawal
Similar Questions
+2 votes

I have a requirement in which I will get data in CSV file. I have to create a JSON file for this data. Please suggest me how I can implement this in Informatica Power Centre.

...