0

For example, givent this JSON object:

{
    name: 'Tony',
    age: '20',
    birthday: '20180101',
}

How can I turn it as parameters to attach to the end of a restful GET API URL like this?

/API/data?name=Tony&age=20&birthday=20180101

Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
Dreams
  • 8,288
  • 10
  • 45
  • 71
  • https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascript-object – amiraliamhh Jun 28 '18 at 16:06
  • 1
    Possible duplicate of [Query-string encoding of a Javascript Object](https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascript-object) – Derek Lawrence Jun 28 '18 at 16:12

1 Answers1

1

You can use jQuery.param function:

var object = {
  name: 'Tony',
  age: '20',
  birthday: '20180101',
};
console.log($.param(object));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34