Home Web Front-end JS Tutorial Use eval to generate JSON objects under js_javascript skills

Use eval to generate JSON objects under js_javascript skills

May 16, 2016 pm 06:19 PM
eval json object

For example: var json = eval('(' ret ')');
Suppose we use PHP's encode_json() on the server side to generate the string that needs to be returned
If the generated string is [{"name" :"boke"},{"age":"23"}],
We can directly use eval([{"name":"boke"},{"age":"23"}]) to generate the corresponding JSON object;
If the generated string is {"name":"boke","age":"23"},
We use eval({"name":"boke","age" :"23"}) An error will occur when generating a JSON object
, we need to write eval(({"name":"boke","age":"23"})) like this.
The writing method of eval(( )) is also applicable to other strings generated by the encode_json() function, including the first case.
You can also use a special

Copy code The code is as follows:
function getdata(data){
 return (new Function("return " data) )();
}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does eval mean in python? What does eval mean in python? May 22, 2019 pm 03:18 PM

eval means "evaluation" and is a built-in function in Python that is used to execute a string expression and return the calculation result of the expression; that is, when assigning a variable, the representation on the right side of the equal sign is written in the format of a string, The return value is the result of this expression. Syntax "eval(expression[, globals[, locals]])".

How to disable eval in php under win How to disable eval in php under win Oct 31, 2022 am 09:33 AM

How to disable eval in PHP under win: 1. Download "PHP_diseval_extension"; 2. Find the PHP currently used by the server; 3. Open the PHP configuration file; 4. Add the "extension=diseval.so" code; 5. Restart the service.

How to get all keys of a JSON object using GSON in Java? How to get all keys of a JSON object using GSON in Java? Aug 30, 2023 pm 11:45 PM

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

A simple explanation of the usage of eval in python A simple explanation of the usage of eval in python Mar 25, 2024 pm 02:08 PM

In Python, the eval() function is used to execute a string expression and return its result. It takes a string containing an expression as a parameter and evaluates the expression. The eval() function is powerful, but it should be noted that it will execute any valid Python expression contained in the string, so you should avoid accepting external input strings when using it to prevent security vulnerabilities.

How can we merge two JSON objects in Java? How can we merge two JSON objects in Java? Aug 26, 2023 am 08:01 AM

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

what is eval in python what is eval in python Aug 08, 2023 pm 05:07 PM

eval is a built-in function in python that is used to parse and execute strings as codes and return the execution results. Since the "eval" function can execute arbitrary Python code, you need to carefully consider security issues when using the "eval" function. If you pass an untrusted string to the "eval" function, it may lead to security issues such as code injection.

How to use JsonConfig in Java to convert bean to JSON object and exclude certain properties? How to use JsonConfig in Java to convert bean to JSON object and exclude certain properties? Sep 01, 2023 pm 06:37 PM

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

How to use Python eval function How to use Python eval function Jun 04, 2023 am 09:19 AM

Python’s eval() We can use the built-in Pythoneval()[1] to dynamically evaluate expressions from string-based or compiled code-based input. If we pass a string to eval(), then the function parses it, compiles it to bytecode[2], and evaluates it as a Python expression. But if we call eval() with a compiled code object, then the function only performs the calculation step, which is very convenient if we call eval() multiple times with the same input. Python's eval() is defined as follows. eval(expression[,globals[,locals]]) this function

See all articles