javascript - which function can i use instead of parseJSONjquery version 1.3.2 - Stack Overflow

admin2025-04-18  0

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...................

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...................

Share Improve this question edited Oct 7, 2011 at 7:26 VolkerK 96.2k20 gold badges168 silver badges232 bronze badges asked Oct 7, 2011 at 7:22 Kanishka PanamaldeniyaKanishka Panamaldeniya 17.6k31 gold badges127 silver badges195 bronze badges 1
  • 2 github./douglascrockford/JSON-js maybe? – Yoshi Commented Oct 7, 2011 at 7:24
Add a ment  | 

4 Answers 4

Reset to default 4

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/js.html Or use one of the existing js libraries to parse JSON. This, for example: https://github./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 ;

}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744971023a277489.html

最新回复(0)