Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
JavaScript
function CallParameter(value) {
    var value;
    if (value = "call") {
    }
    if (value = "sms") {
    }
    if (value = "url") {
    }
}

When i pass call as parameter to the function i should get a phone number from json, and if it is url i should get url from json.
Posted
Updated 17-May-15 22:36pm
v2
Comments
John C Rayan 18-May-15 4:29am    
you would need jQuery.parseJSON(). Whats your JSON structure?
kiran gowda8 18-May-15 7:08am    
{ "call": "9880039959"
"sms": "hello"
"url": "www.google.com"
}
it is the test.json file
John C Rayan 18-May-15 7:50am    
Now just let me know, are you going to invoke Ajax call to server to receive the json data? Have you got any code already? Provide more details...

1 solution

may be you should try this :

C#
var myJSONtext = '{"call": "9880039959","sms": "hello","url": "www.google.com"}' ;
    CallParameter.myObject = eval('(' + myJSONtext + ')');

    function CallParameter(value) {
      if (value!="")
      {
          alert(CallParameter.myObject[value]);
      }
    }

  CallParameter("call")  ;
  CallParameter("sms")  ;
  CallParameter("url")  ;
 
Share this answer
 
Comments
kiran gowda8 19-May-15 1:02am    
thank you crazy999.
kiran gowda8 19-May-15 2:53am    
and is it possible to return data in json format??
i.e. if i pass call as parameter it should return "call":"9900000099" this?

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