


Conversion between json objects and string objects in JavaScript_javascript skills
var json = { aa:true,bb:true};
var json1 = {aa:'b',bb:{cc:true,dd:true}};
1: js Manipulate json object
for(var item in json ){
alert(item); //The result is aa, bb, the type is string
alert(typeof(item));
alert(eval("json." item)); //The result is true, the true type is boolean
eval(("json." item "=false;")); //Change the value of the json object
}
2 : Method to convert json object into String object
/**
* json object to string format
*/
function json2str(o) {
var arr = [];
var fmt = function(s) {
if (typeof s == 'object' && s != null) return json2str(s);
return /^(string|number)$/.test(typeof s) ? "'" s "'" : s;
}
for ( var i in o) arr.push("'" i "':" fmt(o[i]));
return '{' arr.join(',') '}';
}
3: Convert string object to json object
function stringToJson(stringValue)
{
eval("var theJsonValue = " stringValue);
return theJsonValue;
}
4: Method to convert json array into String object (requires the above method)
function JsonArrayToStringCfz(jsonArray)
var JsonArrayString = "[";
for(var i=0;i
}
JsonArrayString = JsonArrayString.substring(0,JsonArrayString.length-1) "]";
return JsonArrayString;
}
5: Use json.js json to string
<script> <br>var date = {myArr : ["a" , " b" , "c" , "d"] , count : 4}; <br>var str = JSON.stringify(date); <br>alert(str); <br></script>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

AGson isalibrarythatcanbeusedtoparseJavaobjectstoJSON andvice-versa.ItcanalsobeusedtoconvertaJSONstringtoanequivalentJavaobject.InordertoparsejavaobjecttoJSONorJSONtojavaobject,weneedtoimportcom.google.gson packageintheJava

JSON is a lightweight data exchange format, and the format of JSON is a key-value pair. JSONObject can parse text in a string to generate map-like objects and supports the java.util.Map interface. We can merge two JSON objects in Java using org.json.simple.JSONObject. We can merge two JSON objects using the putAll() method in the program below (inherited from the interface java.util.Map). Example importjava.util.Date;importorg.json.simple.JSONObject;publicclass

The JsonConfig class is a utility class that helps configure the serialization process. We can use the setExcludes() method of the JsonConfig class to convert a bean into a JSON object and exclude some of its properties, and pass this JSON configuration instance to the parameter of the static method fromObject() of JSONObject. SyntaxpublicvoidsetExcludes(String[]excludes)Inthebelowexample,wecanconvertbeantoaJSONobjectbyexc

Converting HTML to PDF is one of the common requirements in web development. Below you will learn how to implement this functionality using specific code examples. First of all, what needs to be introduced is a commonly used open source library-pdfmake. pdfmake is a JavaScript library for generating PDFs that can specify the structure, style, and content of PDFs by using JSON objects. Before using it, we need to install it via npm: npminstallpdfmake After the installation is complete, I

The serialization process can be configured using the JsonConfig class. We can use JsonConfig's setJsonPropertyFilter() method to set the property filter when serializing to JSON. We need to implement a custom PropertyFilter class by overriding the apply() method of the PropertyFilter interface. Returns true if the attribute will be filtered out, false otherwise. Syntax publicvoidsetJsonPropertyFilter(PropertyFilterjsonPropertyFilter)Exampleimp

Detailed explanation of how to convert a Java array into a List In Java programming, we often encounter the need to convert an array into a List. Java provides a variety of flexible ways to implement this operation. This article will introduce several commonly used methods in detail and give specific code examples. Using the asList method of the Arrays tool class The Arrays tool class is a tool class provided by Java for operating arrays. The asList method can convert an array into the corresponding List. The following is used

Tips for quickly converting Java arrays into Lists require specific code examples. In Java programming, we often encounter the need to convert arrays into Lists. Using List can operate elements more flexibly and provides more methods and functions. The following will introduce several techniques for quickly converting Java arrays into Lists, including using the asList() method of the Arrays class, using the ArrayList constructor, and using the Stream stream in Java8. Method 1: Use Arr

How to use Java code to convert an array into a List. In Java, converting an array into a List is a very common operation. This conversion can be achieved by using Java's own Arrays class or using the StreamAPI introduced in Java 8. Specific code examples are given below. Method 1: Use the asList method of the Arrays class. The Arrays class is a tool class provided by Java for operating arrays. The asList method can convert the array into L
