2015-03-24, 02:09 AM
This is obviously a coding problem on my part but I can't see what's wrong.
If I use Chrome Browser to connect to http://192.168.0.5:8866/public/Library/M...et/Artists I get a sensible result along the lines of...
...but when I try to connect from nDroid with some simple HTTP GET code and log the result of reading the InputStream I see something like the following...
The starting 'ssage' bit is clearly the end of the "rtn" name/value pair but it's overwriting the start of what should be the "Artists" JSON array. The code I'm using is as follows...
I've tried ISO-8859-1 as well as UTF-8 but the result is the same. Any ideas on what I'm missing?
Cheers,
Brian
If I use Chrome Browser to connect to http://192.168.0.5:8866/public/Library/M...et/Artists I get a sensible result along the lines of...
Code:
{"Artists":[{"Artist":"AC-DC"},{"Artist":"Anastacia"},{...},{...}],"rtn":{"Error":false,"HTTPStatus":200,"Message":""}}
...but when I try to connect from nDroid with some simple HTTP GET code and log the result of reading the InputStream I see something like the following...
Code:
ssage":""}}t":"Guided By Voices"},{"Artist":"Garbage"},{"Artist":"Velvet Chain"},{...},{...}<many more but the rest is cut short>
The starting 'ssage' bit is clearly the end of the "rtn" name/value pair but it's overwriting the start of what should be the "Artists" JSON array. The code I'm using is as follows...
Code:
InputStream inStream = connHelper.getInputStream();
int contentLength = connHelper.getContentLength();
// The following line logs 7311
Log.d(TAG, "getArtists() - getContentLength() : " + contentLength);
int totalRead = 0;
int len = -1;
// byte[] buffer = new byte[contentLength != -1 ? contentLength : 8192];
byte[] buffer = new byte[32768];
while ((len = inStream.read(buffer)) != -1)
if (len != 0) {
totalRead += len;
}
// The following line also logs 7311
Log.d(TAG, "getArtists() - totalRead: " + totalRead);
result = HELPER_RESULT.FILE_DOWNLOAD_SUCCESS;
String jsonString = new String(buffer, 0, totalRead, "UTF-8");
Log.d(TAG, jsonString);
I've tried ISO-8859-1 as well as UTF-8 but the result is the same. Any ideas on what I'm missing?
Cheers,
Brian