Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to JSON object in GWT (JSNI)

How to convert a string to a JSON object that I'll use inside JSNI? Thank you.

like image 904
Abdessamad Doughri Avatar asked Dec 05 '25 11:12

Abdessamad Doughri


2 Answers

This is a copy-paste way to do it:

import com.google.gwt.core.client.JsonUtils;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;

...

JSONObject data = new JSONObject(JsonUtils.safeEval(jsonString));
JSONArray array = data.get("anArray").isArray();
JSONObject obj = data.get("anObject").isObject();
like image 129
Daniel De León Avatar answered Dec 07 '25 23:12

Daniel De León


You should look at gwt core JsonUtils which has a safeEval method for the string. You should define a JavaScript Overlay Object for use with the result or you could work with the object in JSNI as you seem to want to.

like image 37
dlamblin Avatar answered Dec 08 '25 01:12

dlamblin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!