Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Blog Reader Android App Getting Data from the Web Getting JSON Data from an HTTP Request

If I am using my own API built with Laravel, how do I set Content-Length for an array?

I've currently got:

Route::get('/api/test/', function() {
    $meals = Posts::all()->toArray();
    return Response::json(['posts' => $posts], 200);
});

I get an error in Android "java.lang.NegativeArraySizeException: -1" which, after searching, is due to no 'Content-Length' being sent, I can set it manually with ['Content-Length' => someValue] but it will mismatch or be too short. How do I set it dynamically like teamtreehouses api?

Thanks!

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You should be able to work around it with some different code in the Android app: https://teamtreehouse.com/forum/parsing-data-returned-in-json-jsonexception-unterminated-string-at-character-5792

Sorry about the trouble!

Thanks for that, all working now. Thanks for the course!