Euphe
Euphe

Reputation: 3709

Get request response is in weird format

I send a get request to a local (separate from app) jetty web server

RestClient.get("ip/command/core/get-version", {})

Then I do a JSON.parse() on the response.

As a result I get

{"revision"=>"r2407", "full_version"=>"2.5 [r2407]", "full_name"=>" [r2407]", "version"=>"2.5"}

What's wrong? How do I turn it into a hash, so I can extract the full_version property?

Upvotes: 0

Views: 115

Answers (2)

alxklo
alxklo

Reputation: 61

Your JSON response looks to be encoded into HTML entities.

If you are using Ruby, try decoding the response using CGI.unescape_html prior to running JSON.parse. Running the result of that method through JSON.parse should give you your hash.

Upvotes: 0

BroiSatse
BroiSatse

Reputation: 44695

String returned by service is html encoded. Try decoding it first:

JSON.parse(CGI.unescape_html(response_body))

Upvotes: 1

Related Questions