I
I
Ilya Bobkov2015-11-09 12:53:25
PHP
Ilya Bobkov, 2015-11-09 12:53:25

How to convert json response to normal?

Hey! I can't parse data on jquery
From php I get a non-standard json response in the form:
[{"id":"1","fio":"??????????","pn":"1", "vt":"1","sr":"1","cht":"1","pt":"2","sb":"1","vs":"1","user_id ":"154","data_reg":"2015-11-18"}]

How to remove extra brackets around the edges:
php:

$result = $mysqli->query( "SELECT * FROM personal WHERE user_id='".$_SESSION["user_id"]."'" );
 if (!$result) error($mysqli->error);
 if ( $result->num_rows > 0 )
 { 
   while($row = $result->fetch_assoc()) 
   {
     $myArray[] = $row;
   }
    echo json_encode($myArray);
 }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-11-09
@alexey-m-ukolov

What the hell is it, non-standard , what the hell are extra brackets if you send an array of objects from the server ...

D
Dmitry, 2015-11-09
@Thelema

[] - JSON array;
{} - JSON object;
[{}] - an array consisting of one element - an object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question