Howto decode JSON from REST "selectQuery" in JAVA Language? - Forum - Rollbase - Progress Community

Howto decode JSON from REST "selectQuery" in JAVA Language?

 Forum

Howto decode JSON from REST "selectQuery" in JAVA Language?

This question is answered

Hi GUY!!

        IN Rollbase Private Cloud 3.2. I want to know howto decode JSON from REST "selectQuery" in JAVA Language?

Such as:
JSON :


[
[ 131227, "Bill", "Smith" ],
[ 131228, "John", "Roth" ]
]

Howto decode JSON in JAVA?

Thanks for Answer

Regards
BOY

Verified Answer
  • Not sure what you are asking for.. Can you give an example ?

    The above data I would use like this in my Java code

    for(int k=0; k< objArrayofArrays.length; k++){
         for(int j=0; j<objArrayofArrays[k].length; j++){
    	Obj obj =  objArrayofArrays[k][j];
            // Cast obj to appropriate type and use
         }
    }

All Replies
  • Hi BOY

    You can use JSON.parse(request);

    developer.mozilla.org/.../parse

  • JAVA It not JavaScript.

  • Ah my bad, found these:

    theoryapp.com/parse-json-in-java

    code.google.com/.../DecodingExamples

    http://www.json.org/java/

  • As of now SelectQuery Json Response is not in json complaint format. Please treat it as String and parse it.

    Thanks

    Satya

  • I tried to everything in reference and It cannot work.

  • Hello,

    Here are two libraries that you can use from Java to parse JSON:

    - Jackson ( http://jackson.codehaus.org )

    - Jettison ( http://jettison.codehaus.org/ )

    You can use JSON Lint ( http://jsonlint.com ) to check that a string is valid JSON.

    I hope this helps.

  • Select Query returns data as a 2D Array.

    Sample JSON Parser Code using Google gson Library where the select Query output String is held in a String variable called jsonString.

    Gson gson = new Gson();
    Object[][] objArrayofArrays = gson.fromJson(jsonString, Object[][].class);


  • You should cast/parse each value based on their data type and use while iterating through the 2D Array

  • You can use http://json.parser.online.fr/ to visualize the JSON.

    Sample for your data..

  • You can also use XML output, this may be easier to use in Java.

  • Thanks a million  Anoop !! and May I ask you a favour?

    Gson gson = new Gson();

    Object[][] objArrayofArrays = gson.fromJson(jsonString, Object[][].class);

    For your example : How to get Array value in GSON?

    Could you send to Example code for me?

    Thank you in advance

    Best Regards

    BOY!!

  • Not sure what you are asking for.. Can you give an example ?

    The above data I would use like this in my Java code

    for(int k=0; k< objArrayofArrays.length; k++){
         for(int j=0; j<objArrayofArrays[k].length; j++){
    	Obj obj =  objArrayofArrays[k][j];
            // Cast obj to appropriate type and use
         }
    }