简体   繁体   中英

Can't parse JSON string to Java/JavaScriptObject in GWT

I receive data from the server in JSON and parse using JsonUtils (GWT). They look like this:

[{"id":26,"name":"Circle1","description":"Test","type":"CIRCLE","coordinates":[{"latitude":50.364736755649716,"longitude":30.120391845703125}],"radius":6577.427847903551,"userId":1}]

I use this code to parse it:

JsArray<Geofence> geofenceJsArray = JsonUtils.safeEval(response.getText());

But I can't get access to the list of coordinates. When I call

geofenceJsArray.get(0).getCoordinates().size()

I receive this error message in browser's console:

Uncaught TypeError: $getCoordinates_1_g$(...).size_54_g$ is not a function

What I'm doing wrong? Thanks in advance!

(From my answer for Generator threw an exception while rebinding , where you posted some of your source:)

You can't have a JavaScriptObject's properties be non-JavaScript types. GWT's generated arrays almost look like js arrays, but will be missing important type details, and java.util.List won't work at all - JS will happily pretend that it will work, and will return a JS array, which has a property called length , but no method called size .

Instead, change your getCoordinates to return JsArray<Coordinate> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM