0

I've the following array in a $arrayResult:

array (size=1)
  'Records' => 
    array (size=1498)
      0 => 
        array (size=4)
          'code' => string '9999999' (length=12)
          'nome' => string 'XXXXXXXXX' (length=39)
          'contrato' => string '67971' (length=5)
          'status' => string 'A' (length=1)
      1 => 
        array (size=4)
          'code' => string '777777777' (length=12)
          'nome' => string 'WWwwwwwww' (length=40)
          'contrato' => string '67725' (length=5)
          'status' => string 'C' (length=1)

    .... (other results with the same pattern)

    $resultArray = $view->getAllAccounts();
    $final['Records'] = $resultArray;
    echo json_encode($final, true);

when I get the array and use the json_encode nothing happens.

4
  • peculiar looking php array - how is this derived? Commented Nov 12, 2015 at 15:27
  • try $final = $resultArray; Commented Nov 12, 2015 at 15:33
  • 1
    json_encode expects the second parameter to be an integer, why do you provide a boolean? Commented Nov 12, 2015 at 15:37
  • I think you are confusing the second parameter of json_encode() with the second parameter of json_decode() Remove the second parameter from this line echo json_encode($final, true); to be echo json_encode($final); Commented Nov 12, 2015 at 15:43

1 Answer 1

4

Regardless of the data-structures and code you wrote so far, if you encounter unexpected behaviour using json_decode and json_encode, use json_last_error and/or json_last_error_msg to see what happened.

Sign up to request clarification or add additional context in comments.

3 Comments

perfect, didnt know about this: the error msg is Malformed UTF-8 characters, possibly incorrectly encoded
after encoding the contrato field to utf8(utf8_encode) it works flawless! my code to json_encode is fine, the utf8 string was the problem tks.
:-) nice, glad it was that easy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.