7
Così ho un oggetto JSON, che ha una struttura in questo modo:PHP Search JSON per il valore
{
"John Doe": [
{
"childName": "Harry",
"childAge": 15,
"childGender": "Male"
},
{
"childName": "Sally",
"childAge": 9,
"childGender": "Female"
},
],
"Miss Piggy": [
{
"childName": "Jane",
"childAge": 20,
"childGender": "Female"
}
],
}
Quello che voglio fare è essere in grado di fare una query per il childName, childAge , o childGender, e restituire quell'oggetto secondario se è stato trovato.
Ad esempio:
searchJson($jsonObj, 'childName', 'Sally') // returns {"childName":"Sally", "childAge":9,"childGender":"Female"}
Quale sarebbe il metodo in corso in questo Best?
Non dimenticare di 'json_decode' !!! –
@JosephSilber: '$ obj' è un oggetto' stdClass', che sarebbe il risultato di 'json_decode()'. –
Semplice logica, funziona! Grazie – Baehr