Converts the JavaScript value to a JavaScript Object notation (Json) string.
Json.stringify (value [, Replacer] [, space])
UseJson.stringify Converts the contact object to JSON text. defines an MemberFilter array to convert only surname and phone members. omit the FirstName member.
varContact =NewObject (); Contact.firstname= "Jesper"; Contact.surname= "Aaberg"; Contact.phone= ["555-0100", "555-0120"];varMemberFilter =NewArray (); memberfilter[0] = "surname"; memberfilter[1] = "Phone";varJsontext = json.stringify (Contact, memberfilter, "\ T"));d ocument.write (jsontext);//Output://{"Surname": "Aaberg", "Phone": ["555-0100", "555-0120"]}
use json.stringify with an array. The Replacetoupper function converts each string in an array to uppercase.
varContinents =NewArray (); continents[0] = "Europe"; continents[1] = "Asia"; continents[2] = "Australia"; continents[3] = "Antarctica"; continents[4] = "North America"; continents[5] = "South America"; continents[6] = "Africa";varJsontext =json.stringify (continents, replacetoupper);functionreplacetoupper (key, value) {returnvalue.tostring (). toUpperCase ();}//Output://"Europe,asia,australia,antarctica,north america,south america,africa"
Use the ToJSON method to convert a string value to uppercase.
varContact =NewObject (); Contact.firstname= "Jesper"; Contact.surname= "Aaberg"; Contact.phone= ["555-0100", "555-0120"];contact.tojson=function(key) {varReplacement =NewObject (); for(varValinch This) { if(typeof( This[Val]) = = = ' String ') Replacement[val]= This[Val].touppercase (); ElseReplacement[val]= This[Val]}returnreplacement;};varJsontext =json.stringify (Contact);d ocument.write (jsontext);//Output:{"FirstName": "JESPER", "surname": "Aaberg", "Phone": ["555-0100", "555-0120"]}' {"FirstName": "JESPER", "surname": "Aaberg", "Phone": ["555-0100", "555-0120"]} ' * * *
json.stringify function (JavaScript)