doujia2386 2013-03-16 16:38
浏览 8
已采纳

更改字符串的格式

Hello My question is that i will have a textarea which i want to paste the following

[{"1173627548":{"methv":"dont know","q1":"-","q2":"-","q3":"U","q4":"-","comm":""}},{"1173627548":{"methv":"dont know","q1":"-","q2":"-","q3":"U","q4":"-","comm":""}}]

is there any way i can run a loop which allows me to manipulate the data individually so i can update this to the database. so the first time i run the loop is get this:

{"1173627548":{"methv":"dont know","q1":"-","q2":"-","q3":"U","q4":"-","comm":""}}

if possible i want to strip out the {'s and :'s and "s so i am left with the commas and the data. For example:

1173627548,methv,dont know.. etc

sorry if i am unclear with my question in any way.

  • 写回答

1条回答 默认 最新

  • dongyang5716 2013-03-16 16:45
    关注
    $myhugejson = 'blah...';
    
    $array = json_decode($myhugejson, true);
    
    foreach($array as $sub) {
        print_r($sub);
    
        echo $thing = $sub[0]['methv'];
        echo $second = $sub[0]['q1'];
    }
    

    In each iteration, $sub should contain your list.

    All of this is assuming you're using JSON, which I think that is.

    To reference i

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据