关于JSON总结

1-JSON.parse函数

  作用:将JSON字符串转为JSON对象。

  语法:JSON.parse(text[,reviver]).

  参数:text 必须;一个有效的json字符串。

  返回值:一个对象或者数组。

  eg:

   var json = '{"name":"GET","age":"23","University":"GDUT"}';

   var info = JSON.parse(json);

   document.write(info.name+' is a student of '+info.University + ' and he is '+ info.age + "years old.");

2-JSON.stringfity()函数

  作用:将json对象转换成json字符串。

  语法:JSON.stringfity(value[,replacer][,space])

  参数:value 必须;通常为对象或数组

     replacer 可选。用于转换结果的函数或者数组

     space 可选。向返回值JSON文本添加缩进、空格和转行符以使其更易于读取。

  返回值:一个包含JSON文本的字符串。

  eg:

   var info ={name:"GDT",age:23,University:"GDUT"};

   var json =JSON.stringify(info);

   document.write(json);//{"name":"GDT","age":23,"University":"GDUT"}

@学无先后,达者为师

https://www.cnblogs.com/vanl/p/5466670.html

     

原文地址:https://www.cnblogs.com/yuanguliang/p/10033856.html