简体   繁体   中英

which function can i use instead of parseJSON jquery version 1.3.2

hi i am using jquery version 1.3.2 , i use it because my jquery validation plugin does not work properly with jquery 1.6.2 , but when using version 1.3.2

parseJSON is not a function 

appears in firebug . i searched and found the answer that is because

parseJSON was added in version 1.4.1

so what function can i use instead of parseJSON

please help...................

You may use JSON.Parse() .

var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';
var contact = JSON.parse(jsontext);
var fullname = contact.surname + ", " + contact.firstname;

You can always eval() JSON http://www.json.org/js.html Or use one of the existing js libraries to parse JSON. This, for example: https://github.com/douglascrockford/JSON-js (Yoshi first :-) )

You could add one yourself:

jQuery.parseJSON = function(json) {
  if(JSON && typeof JSON.parse === 'function') return JSON.parse(json);
  else return eval('(' + json + ')');
};

this will check if there is native JSON support and use that when available, else it will use the eval method (see also here )

Try This ,,

<button onclick="myFunction()">Try it</button>

  <script>
  function myFunction() {
   var obj = JSON.parse('{ "name":"mohsen", "age":26}').myChartZ("myChart3");
   document.getElementById("demo").innerHTML.jsonfile = obj.name + ", " + obj.age ;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM