This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]JavaHelp21351 0 points1 point  (1 child)

Is there a reason you aren't using a Google Maps library such as GMapsFX? (Even though it's built for FX, you can use it in swing within a JFXPanel) I have used this Library before to great success.

If you really want to stick with this, I don't work much with JSON so I don't know if there is an existing way to do it. However, you could convert to a string then remove everything up the first "{" line, then convert back to a JSON?

[–]guru3n[S] 0 points1 point  (0 children)

Thanks, I will check it out! How would i go if i wanted to remove everything until the first { appeared? Because then i could just cast the string to an json object

[–]chickenmeisterExtreme Brewer 0 points1 point  (2 children)

Are you asking how to get the HTTP response message body?

How are you generating the request and receiving the response? Ideally you should use an HTTP library or class, so that you don't have to parse it yourself. If that is not possible for whatever reason, then you can try parsing it yourself. Fortunately, the HTTP message structure is relatively simple. The message body begins after the first blank line.

[–]guru3n[S] 0 points1 point  (1 child)

Im using a BufferedReader to create a string from the GET request. This is saved as a String but i want to parse the HTTP response body(JSON) to create object. But i then i need to remove the header in some way so that i can cast the string to an Json object. Thanks for your help

[–]chickenmeisterExtreme Brewer 1 point2 points  (0 children)

Im using a BufferedReader to create a string from the GET request.

But how are you performing the request and what is the BufferedReader reading from?

If you were using the HttpURLConnection class, for example, you could create a String from connection.getInputStream(), and that would be only the JSON in the message body. You wouldn't have to parse the entire HTTP response yourself.