json decode and access?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

json decode and access?

jehanzaibkiani
Hi team,

I have another application storing the json encoded object in the redis cache.

I read we can fetch using cache_fetch by passing the key. This is perfect but I cant find a function to decode the json I have since my other application is encoding the json object and putting into the redis. I need a function to decode it first.

Second question is, after the decode the object is like 

Object
(
    [id] => 161
    [user] => xxx
    [xx] => xxxx
    [xxxx] => xxxx
)

How to access user for example ? 

Thank you 


--
Regards,
Jehanzaib

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Thanks,

Jehanzaib
Reply | Threaded
Open this post in threaded view
|

Re: json decode and access?

Richard Revels
I'm using a webserver response rather than cache_fetch but this may help.

                        #we got a valid response from the web server.  convert from string to json object
                        $json(resp-obj) := $avp(router-resp);
                        if( $avp(ok_log_this) == "true" )
                                xlog("L_INFO", "the whole object returned is $json(resp-obj) and the json route first choice is $json(resp-obj/routes[0]/ruri) \n");

...
                                        if( $json(resp-obj/lang) )
                                        {
                                                $avp(jsonLangPref) := $json(resp-obj/lang);
                                                $avp(jsonStatus) := $json(resp-obj/status);
                                                $avp(jsonSID) := $json(resp-obj/sid);
                                                $avp(jsonDashAddress) := $json(resp-obj/caller_id);
...
and so on.

 



On Thu, Aug 2, 2018 at 6:44 PM J E H A N Z A I B <[hidden email]> wrote:
Hi team,

I have another application storing the json encoded object in the redis cache.

I read we can fetch using cache_fetch by passing the key. This is perfect but I cant find a function to decode the json I have since my other application is encoding the json object and putting into the redis. I need a function to decode it first.

Second question is, after the decode the object is like 

Object
(
    [id] => 161
    [user] => xxx
    [xx] => xxxx
    [xxxx] => xxxx
)

How to access user for example ? 

Thank you 


--
Regards,
Jehanzaib
_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users