[BUG- IGN3049] Decoding json with UTF-8 characters

Hello,
I am using system.util.jsonDecode() function after getting httpget() request. But when I do that, I am not getting properly some characters in Turkish language. so How can I get that value with correct characters ?

I just tried this with a file and got some interesting results – Turkish in the top level decodes fine, but as part of nested object it’s not acceptable. I’ll file a ticket for this. :flushed:

If you’re on 8.0.6+, I’d recommend using system.net.httpClient().get(), which has a more direct ability to decode JSON content (and goes through a different codepath that hopefully avoids the encoding issue)
https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient

client = system.net.httpClient()
response = client.get(MY_URL,params={MY_PARAMS})
returnDict = system.util.jsonDecode( response[‘data’] ) # here data is returned array that includes dictionaries

I tried that code above but I am getting error like below picture.

Hello PGriffith,

client = system.net.httpClient()
response = client.get(MY_URL,params={MY_PARAMS})
returnDict = system.util.jsonDecode( response[‘data’] ) # here data is returned array that includes dictionaries

I tried that code above but I am getting error like below picture.By the way we are using ignition version 8.0.12 and it is suitable version for what we did as you say.

In advance thanks for your helps Kathy :slight_smile:

You don’t need to use system.util.jsonDecode if you’re using httpClient.

client = system.net.httpClient()
response = client.get(MY_URL,params={MY_PARAMS})
returnDict = response.json["data"]

As seen in the picture above, I did what you said @PGriffith but, it was not the solution of the problem unfortunately. Still I have not found a way that I can get httpresponse from server with special characters. As seen in the picture, response has still meaningless characters against my request to the server. any ideas?

In the code you’re printing result from system.net.httpGet, not response from httpClient. Also, what about if you try to retrieve the response as text using a specific charset (UTF-8 should be able to handle Turkish just fine, but it’s possible the server is sending a different encoding without a proper Content-Type header?)

Yes, you are fully right that I did not be careful while printing right result sorry for that. Just now, I tried the code that is in below picture and it works fine with that way.

in the code, as you said I used httpClient.get and .getText() method on response. It returns a text and I convert text to json through json lib in python. In conclusion, result is good. I tried other methods of response value such as .getJson([encoding]) and .json but they showed me the same char problems in the results.

Maybe there can be such a different ways to overcome that problem and it is just one of them. Thanks for all kind support :slight_smile:

1 Like