dongmaqiu6084 2013-09-18 09:18
浏览 256
已采纳

将属性添加到JSON属性PHP中

first of all i have to tell that i'm completly new to php coding and JSON format.

Hi have data from my app to write on my server, to do this i'm using JSON.

When the app starts for the first i make my request for the server to create the JSON file with empty attribute. The file looks like this :

{"dicHistoriqueCours":[],"dicHistoriqueDevoir":[],"dicHistoriqueInterroDone":[],"dicHistoriqueInterroCorrigee":[]}

if i want to add an attribute into this file i can do this using :

$jsonContent = json_decode($content,true); 
$dicCurrentContent['dic'] = $currentDic;   

This code adds an attribute into my JSON File, that's fine but what i want to do is do add $currentDic into one of my attribute (dicHistoriqueCours)

To do that i use :

$jsonContent = json_decode($content,true); 
$dicCurrentContent = $jsonContent['dicHistoriqueCours'];
$dicCurrentContent['dic'] = $currentDic;  

It gave me nothing, i've tried multiple solutions all night long, can someone help me ?

Thank you very much.

  • 写回答

1条回答 默认 最新

  • drxnfdx798517235 2013-09-18 09:20
    关注

    You may try this if I understood your question correctly:

    $jsonContent                         = json_decode($content,true); 
    $jsonContent['dicHistoriqueCours'][] = $currentDic; #add an element to array dicHistoriqueCours
    print_r( $jsonContent );die;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信