How to get the correct Java string from the Python string 'Oslobo \ xc4 \ x91enja'? How to decode it? I tried, I think, everything, everywhere, everywhere, I was stuck for 2 days with this problem. Please, help!
Here is a Python web service method that returns the JSON from which its Java client with Google Gson parses.
def list_of_suggestions(entry): input = entry.encode('utf-8') """Returns list of suggestions from auto-complete search""" json_result = { 'suggestions': [] } resp = urllib2.urlopen('https://maps.googleapis.com/maps/api/place/autocomplete/json?input=' + urllib2.quote(input) + '&location=45.268605,19.852924&radius=3000&components=country:rs&sensor=false&key=blahblahblahblah')
Here is the solution on the Java client
private String python2JavaStr(String pythonStr) throws UnsupportedEncodingException { int charValue; byte[] bytes = pythonStr.getBytes(); ByteBuffer decodedBytes = ByteBuffer.allocate(pythonStr.length()); for (int i = 0; i < bytes.length; i++) { if (bytes[i] == '\\' && bytes[i + 1] == 'x') {
source share