Howto decode JSON from REST "selectQuery" in JAVA

Posted by tanagorns@progress.in.th on 08-May-2015 04:57

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

Posted by Anoop Premachandran on 11-May-2015 03:32

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

Posted by ByronB on 08-May-2015 05:02

Hi BOY

You can use JSON.parse(request);

developer.mozilla.org/.../parse

Posted by tanagorns@progress.in.th on 08-May-2015 05:14

JAVA It not JavaScript.

Posted by ByronB on 08-May-2015 05:33
Posted by satyanarayana sunku on 08-May-2015 05:40

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

Thanks

Satya

Posted by tanagorns@progress.in.th on 08-May-2015 05:55

I tried to everything in reference and It cannot work.

Posted by egarcia on 08-May-2015 07:10

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.

Posted by Anoop Premachandran on 08-May-2015 07:50

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);


Posted by Anoop Premachandran on 08-May-2015 07:52

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

Posted by Anoop Premachandran on 08-May-2015 07:59

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

Sample for your data..

Posted by pvorobie on 08-May-2015 11:34

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

Posted by tanagorns@progress.in.th on 08-May-2015 23:16

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!!

Posted by Anoop Premachandran on 11-May-2015 03:32

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
     }
}

This thread is closed