Click here to Skip to main content
15,936,337 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello
is it possible to change the users into a json link ?

i want to change it become : users: http://localhost/../.../..json
here is the example :
JavaScript
$("#default-textarea").mention({
           users: [{
               name: 'Lindsay Made',
               username: 'LindsayM',
               image: 'http://placekitten.com/25/25'
           }, {
               name: 'Rob Dyrdek',
               username: 'robdyrdek',
               image: 'http://placekitten.com/25/24'
           }, {
               name: 'Rick Bahner',
               username: 'RickyBahner',
               image: 'http://placekitten.com/25/23'
           }, {
               name: 'Jacob Kelley',
               username: 'jakiestfu',
               image: 'http://placekitten.com/25/22'
           }, {
               name: 'John Doe',
               username: 'HackMurphy',
               image: 'http://placekitten.com/25/21'
           }, {
               name: 'Charlie Edmiston',
               username: 'charlie',
               image: 'http://placekitten.com/25/20'
           }, {
               name: 'Andrea Montoya',
               username: 'andream',
               image: 'http://placekitten.com/24/20'
           }, {
               name: 'Jenna Talbert',
               username: 'calisunshine',
               image: 'http://placekitten.com/23/20'
           }, {
               name: 'Street League',
               username: 'streetleague',
               image: 'http://placekitten.com/22/20'
           }, {
               name: 'Loud Mouth Burrito',
               username: 'Loudmouthfoods',
               image: 'http://placekitten.com/21/20'
           }]
       });
Posted
Comments
Sinisa Hajnal 5-Mar-15 2:04am    
Change user into json link? What does it mean? What do you want to change into what? Unclear

1 solution

Although your question is not so clear but as your question Heading implies you want to convert your javascript array (users) to json.So I give you a solution.Happy coding. :)


JavaScript
<script type="text/javascript">

       function JavascriptArrayToJSON() {
           var users = [{
               name: 'Lindsay Made',
               username: 'LindsayM',
               image: 'http://placekitten.com/25/25'
           }, {
               name: 'Rob Dyrdek',
               username: 'robdyrdek',
               image: 'http://placekitten.com/25/24'
           }, {
               name: 'Rick Bahner',
               username: 'RickyBahner',
               image: 'http://placekitten.com/25/23'
           }, {
               name: 'Jacob Kelley',
               username: 'jakiestfu',
               image: 'http://placekitten.com/25/22'
           }, {
               name: 'John Doe',
               username: 'HackMurphy',
               image: 'http://placekitten.com/25/21'
           }, {
               name: 'Charlie Edmiston',
               username: 'charlie',
               image: 'http://placekitten.com/25/20'
           }, {
               name: 'Andrea Montoya',
               username: 'andream',
               image: 'http://placekitten.com/24/20'
           }, {
               name: 'Jenna Talbert',
               username: 'calisunshine',
               image: 'http://placekitten.com/23/20'
           }, {
               name: 'Street League',
               username: 'streetleague',
               image: 'http://placekitten.com/22/20'
           }, {
               name: 'Loud Mouth Burrito',
               username: 'Loudmouthfoods',
               image: 'http://placekitten.com/21/20'
           }]

           var jsonResult;

           var string_json;
           string_json =JSON.stringify(users);

           jsonResult = JSON.parse(string_json);  //Here is your json



       }

   </script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900