lundi 22 juillet 2019

How to query with muti-level json in laravel

I wanna make a search function to search some data in a json.

the json is like this:

{"type1":{
        "pd1":{
             "price":"110","detail":{
                                   "QAQ":{
"a":"0","b":"0","c":"0","d":"0"},
"TATTT":{"QwQ":"0","TwT":"0","QAQ":"0","TAT":"0"}}},
"type2":{
        "pd2":{
             "price":"50","detail":{"d1":{"w1":0,"w2":0}}},"pd3":{"price":"10","detail":{}}}}

example:

search("110")

I expect get {"type1":{"pd1":{"price":"110","detail":{"QAQ":{"a":"0","b":"0","c":"0","d":"0"},"TATTT":{"QwQ":"0","TwT":"0","QAQ":"0","TAT":"0"}}}}

search("pd3")

get

{"type2":{"pd3":{"price":"10","detail":{}}}}

and then

search("w")

get

{"type1":{"pd1":{"price":"110","detail":{"QAQ":{"a":"0","b":"0","c":"0","d":"0"},"TATTT":{"QwQ":"0","TwT":"0","QAQ":"0","TAT":"0"}}}, "type2":{"pd2":{"price":"50","detail":{"d1":{"w1":0,"w2":0}}}}}

try to use Jsonq,but not success

$jsonq = new Jsonq();
    $jsonq->json($json_data);
    $res = $jsonq->where("price",'=',"110")
    ->get();
dump($res);
#retuen only []

Maybe Jsonq can only search one level.

I don't know how to make json neat on stackoverflow QAQ



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire