convert query String to json in php

前端 未结 3 586
孤独总比滥情好
孤独总比滥情好 2021-01-07 02:49

I send a QueryString formatted text like bellow to a php Script via Ajax:

title=hello&custLength=200&custWidth=300  

And I want to

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 03:31

    The easiest way how to achiev JSON object from $_GET string is really simple:

    json_encode($_GET)
    

    this will produce the following json output:

    {"title":"hello","custLength":"200","custWidth":"300"}
    

    Or you can use some parse function as first (for example - save all variables into array) and then you can send the parsed output into json_encode() function.

    Without specifying detailed requirements, there are many solutions.

提交回复
热议问题