I use php and laravel. I have a column named MsgBody. In this column, there is an array as follows. I want to get the value of “conversationDesc” from this array. What should I do in the Controller and blade part for this?
"MsgBody": [ { "MsgType": "TIMCustomElem", "MsgContent": { "Desc": "", "Data": "{"conversationDesc":"abc","deviceType":"Android","otherUserMsg":false,"sender":{"birthday":"","city":"","coin":9018,"diamonds":990992,"emotional_state":"gizlilik","family_chieftain":0,"family_id":0,"fans_count":0,"focus_count":1,"follow_id":0,"gameCurrency":990992,"gh_status":0,"head_image":"http://fw25live.oss-cn-beijing.aliyuncs.com/public/attachment/202101/29/16/6013cc8481bbc.png","is_admin":0,"is_agree":1,"is_authentication":0,"is_edit_sex":0,"is_guardian":0,"is_noble_mysterious":0,"is_open_shop":0,"is_remind":1,"is_vip":0,"item":{"Yaş":"tahmin edersiniz","Medeni durum":"gizlilik","Meslek":"host","LopMeID":"106050"},"job":"host","levelImageResId":2131232827,"login_type":0,"luck_num":"","luck_num_url":"https://test99.lopme.net/wap/index.php?ctl=luck&act=index","members_url":"https://test99.lopme.net/wap/index.php?ctl=vip_pay&act=purchase","n_svideo_count":0,"nick_name":"ibrahimozden","nick_nameFormat":"ibrahimozden:","noble_avatar":"","noble_barrage":0,"noble_car":0,"noble_car_name":"","noble_car_url":"","noble_experience":0,"noble_icon":"","noble_is_avatar":0,"noble_medal":0,"noble_name":"","noble_silence":0,"noble_special_effects":0,"noble_stealth":0,"noble_vip_type":0,"open_podcast_goods":0,"pay_car":"https://test99.lopme.net/wap/index.php?ctl=car&act=index","podcast_goods":0,"podcast_order":0,"podcast_pai":0,"proUser":true,"province":"","seconds":0,"selected":false,"sex":1,"sexResId":2131231724,"shop_goods":0,"shopping_cart":0,"showId":"106050","show_podcast_goods":0,"show_podcast_order":0,"show_podcast_pai":0,"show_shopping_cart":0,"show_svideo":1,"show_user_order":0,"show_user_pai":0,"signature":"","society_chieftain":0,"society_id":0,"society_name":"","sort_num":-1,"star_box":"","stealth":0,"ticket":1806,"token":"","use_diamonds":9018,"useable_ticket":1806,"user_id":"106050","user_level":25,"user_order":0,"user_pai":0,"v_explain":"","v_icon":"","v_type":"0","video_count":0,"viewer_guard_type":0,"vip_expire_time":"Açılmadı"},"text":"abc","type":20}", "Ext": "", "Sound": "" } } ]
Advertisement
Answer
It seems that your data are JSON. You can decode this using json_decode
.
You should be able to access what you want with something like:
$column = [ "MsgBody" => [ [ "MsgType" => "TIMCustomElem", "MsgContent" => [ "Desc" => "", "Data" => "{"conversationDesc":"abc","deviceType":"Android","otherUserMsg":false,"sender":{"birthday":"","city":"","coin":9018,"diamonds":990992,"emotional_state":"gizlilik","family_chieftain":0,"family_id":0,"fans_count":0,"focus_count":1,"follow_id":0,"gameCurrency":990992,"gh_status":0,"head_image":"http://fw25live.oss-cn-beijing.aliyuncs.com/public/attachment/202101/29/16/6013cc8481bbc.png","is_admin":0,"is_agree":1,"is_authentication":0,"is_edit_sex":0,"is_guardian":0,"is_noble_mysterious":0,"is_open_shop":0,"is_remind":1,"is_vip":0,"item":{"Yaş":"tahmin edersiniz","Medeni durum":"gizlilik","Meslek":"host","LopMeID":"106050"},"job":"host","levelImageResId":2131232827,"login_type":0,"luck_num":"","luck_num_url":"https://test99.lopme.net/wap/index.php?ctl=luck&act=index","members_url":"https://test99.lopme.net/wap/index.php?ctl=vip_pay&act=purchase","n_svideo_count":0,"nick_name":"ibrahimozden","nick_nameFormat":"ibrahimozden:","noble_avatar":"","noble_barrage":0,"noble_car":0,"noble_car_name":"","noble_car_url":"","noble_experience":0,"noble_icon":"","noble_is_avatar":0,"noble_medal":0,"noble_name":"","noble_silence":0,"noble_special_effects":0,"noble_stealth":0,"noble_vip_type":0,"open_podcast_goods":0,"pay_car":"https://test99.lopme.net/wap/index.php?ctl=car&act=index","podcast_goods":0,"podcast_order":0,"podcast_pai":0,"proUser":true,"province":"","seconds":0,"selected":false,"sex":1,"sexResId":2131231724,"shop_goods":0,"shopping_cart":0,"showId":"106050","show_podcast_goods":0,"show_podcast_order":0,"show_podcast_pai":0,"show_shopping_cart":0,"show_svideo":1,"show_user_order":0,"show_user_pai":0,"signature":"","society_chieftain":0,"society_id":0,"society_name":"","sort_num":-1,"star_box":"","stealth":0,"ticket":1806,"token":"","use_diamonds":9018,"useable_ticket":1806,"user_id":"106050","user_level":25,"user_order":0,"user_pai":0,"v_explain":"","v_icon":"","v_type":"0","video_count":0,"viewer_guard_type":0,"vip_expire_time":"Açılmadı"},"text":"abc","type":20}", "Ext" => "", "Sound" => "" ] ] ] ]; $firstMessageContent = $column["MsgBody"][0]["MsgContent"]; $decodedData = json_decode($firstMessageContent["Data"], true); $conversationDesc = $decodedData["conversationDesc"]; assert($conversationDesc === "abc");