I have to pass an array from a php file to python file but my code is giving output NULL

前端 未结 2 534
迷失自我
迷失自我 2020-12-22 00:00

PHP code:



        
2条回答
  •  悲&欢浪女
    2020-12-22 00:40

    There is incorrect data for json.dump() in Python

    # Generate some data to send to PHP
    result = {'23','4'}
    

    So this give error, not json string

    import sys, json
    
    # Generate some data to send to PHP
    result = {'23','4'}
    
    # Send it to stdout (to PHP)
    print json.dumps(result)
    

    and PHP get NULL as $result from Python so you get NULL on screen - in browser

    Use (for example):

    # Generate some data to send to PHP
    result = {'a':'23','b':'4'}
    

    and json.dump() will work fine.

提交回复
热议问题