-1

I'm currenly writing a basic API, this is just the simple GET and return of some records in a database, so they are all been pushed into an array and returned using json_encode.

But the problem I'm facing is the text; is there a limit? as when i remove the text part it displays each record in JSON format but when i add the text field back in the whole return just gives white page, i have all errors turned on and there is nothing displayed on screen errors or in php error logs.

$review = array(
   "ReviewID" => $reviewID,
   "Reviewer" => $reviewer,
   "Photo" => $reviewerPhoto,
   "Stars" => $reviewStars,
   "Title" => $reviewTitle,
   "Review" => $reviewText,
   "Date" => $reviewDate,
   "Since" => $timeSince,
   "From" => $reviewFrom
);
array_push($reviewArray, $review);
echo json_encode($apiReturn);

So the Array field Review should be able to contain the text from the review, this is stored using (TEXT) in the database and some reviews do contain a-lot of characters.

Not sure if there was a limit to what you can display, any help or advice would be great.

2 Answers2

0

Assuming that your review text is not super big (which could lead to memory problems), there shouldn't be any problem. json_encode should not have any problem processing an array of strings.

The documentation mentions that "All string data must be UTF-8 encoded", but I think this should in the worst case cause some encoding problem.

Try to be more specific than "the whole return breaks", if you just see a blank page or a generic error page, you should try to enable error display. Relevant thread: Showing all errors and warnings

AsTeR
  • 7,247
  • 14
  • 60
  • 99
0

you can try below example to check error in json encode

$json = json_encode($data);

if ($json)
    echo $json;
else
    echo json_last_error_msg();

PHP docs here: http://php.net/manual/en/function.json-last-error-msg.php

Abhijeet Navgire
  • 683
  • 7
  • 20