create nested JSON object in php?

后端 未结 7 829
广开言路
广开言路 2020-12-09 16:25

I don\'t work with php much and I\'m a little fuzzy on object creation. I need to make a webservice request sending json and I think I have that part covered. Before I can

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 16:56

    You can use json_encode to encode a php array http://php.net/manual/en/function.json-encode.php

    $theArray = array('client'= array('build'=>'1.0', 
                                    'name'=>'xxxxx', 
                                    'version'=>'1.0'
                                   ), 
                    'protocolVersion'=> 4, 
                    'data'=> array('distributorId'=>'xxxx', 
                                   'distributorPin'=>'xxxx', 
                                   'locale'=>'en-US' 
                                   ) 
                    );
    
    $theObj = json_encode($theArray);
    

    hopefully this helps..

    posted it, then seen loads of answers already! :|

提交回复
热议问题