NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 4 5 6 7 8 … 93 Next »
NEWA JSON API oddity

 
  • 0 Vote(s) - 0 Average
NEWA JSON API oddity
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#1
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...

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
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,112
Threads: 957
Joined: May 2006
#2
2015-03-24, 02:50 AM
What about a valid return of zero when the socked is blocked or a short read?

Martin
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#3
2015-03-25, 01:49 AM
mvallevand Wrote:What about a valid return of zero when the socked is blocked or a short read?

Martin
Yep, 'len' can be zero but it won't cause the 'while' loop to exit. I've done some more tests with extra logging and it seems it's taking 4 or 5 attempts to read the response which seems a bit odd for just 7311 bytes. That'll explain why the buffer was being overwritten though. I've now tried with...
Code:
BufferedReader response = new BufferedReader(new InputStreamReader(inStream));
String strLine = null;
while ((strLine = response.readLine()) != null) {
    sb.append(strLine);
    Log.d(TAG, "getArtists - sb.length() : " + sb.length());
}
...but that only does one readLine and tells me it has read 7307 bytes (characters?) but it seems to only read about half of what I see in the browser. Very odd.
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#4
2015-03-25, 03:23 AM
OK folks, just ignore this. A problem with Android logging (it was only showing a partial string when it actually had the full result) and a sneaky bug elsewhere (now fixed) meant I was thrown off at a tangent. Oh well, these things are sent to try us. Sigh.

Cheers,
Brian
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  How to convert the startTIme value in json response? JavaWiz 3 1,975 2020-04-25, 12:35 AM
Last Post: JavaWiz
  Discover NEWA version? bgowland 2 1,939 2014-01-06, 04:40 AM
Last Post: bgowland
  NEWA - using buffer file produced by /public/VLCService?Channel= bgowland 5 2,918 2014-01-02, 06:36 AM
Last Post: bgowland
  Newtonsoft.Json mvallevand 9 4,209 2013-08-15, 05:10 PM
Last Post: whurlston
  Using JSON with C# bgowland 3 4,049 2011-06-29, 01:48 AM
Last Post: whurlston

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode