Currently getting json results:
{
"post_company_success_company_address_ibfk_1": [
"123 Main Street N\/A Cincinnati Ohio 45500"
]
}
The goal is include address as a separate JSON object in an array attribute of the company object.
I have tried this:
$real= json_encode(['post_company_success_'.$randomname => {[ $result2]}], JSON_PRETTY_PRINT);
It did not work.
1 Answer 1
The trick with JSON encoding is to structure your data into a singular object of some kind, typically some kind of array, and then call json_encode on it once.
For example:
json_encode([ 'key1' => $data1, 'key2' => $data2 ]);
If you concatenate multiple JSON documents together that's not valid from a JSON perspective, so any assembly you perform will need to be undone on the receiving end before processing and parsing.
There are quasi-standards like JSON Lines or Line-Delimited JSON which specify how to encode multiple documents, but these are outside of the JSON specification itself.
$_POST,$_GETor any user data directly in your query. Refer to PHP The Right Way for general guidance and advice.JSON.parse. If you have multiple documents, split them apart and process them individually.$combo?