Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
173 views
Welcome To Ask or Share your Answers For Others

1 Answer

(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>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...