How to pass a JSON array as a parameter in URL

前端 未结 9 1247
一整个雨季
一整个雨季 2020-11-28 10:35

I have an requirement to pass a some values from mobile to server in a web service call and so I am planning to pass all the values in JSON format like the below

<         


        
9条回答
  •  半阙折子戏
    2020-11-28 10:53

    As @RE350 suggested passing the JSON data in the body in the post would be ideal. However, you could still send the json object as a parameter in a GET request, decode the json string in the server-side logic and use it as an object.

    For example, if you are on php you could do this (use the appropriate json decode in other languages):

    Server request:

    http://?param1={"nameservice":[{"id":89},{"id":3}]}
    

    In the server:

    $obj = json_decode($_GET['param1'], true);
    $obj["nameservice"][0]["id"]
    

    out put:

    89
    

提交回复
热议问题