In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how jquery converts objects into strings". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how jquery converts objects into strings".
one. Conversion between Json object and Json string
The conversion methods supported by the 1.jQuery plug-in:
$.parseJSON (jsonstr); / / jQuery.parseJSON (jsonstr), which can convert json strings into json objects
two。 Browsers such as Firefox,chrome,opera,safari,ie9,ie8 supported by browsers:
JSON.stringify (obj) converts JSON to a string. JSON.parse (string) converts a string to JSON format
Var a =
Var baked goods'
Var aToStr=JSON.stringify (a)
Var bToObj=JSON.parse (b)
Alert (typeof (aToStr));? / / string
Alert (typeof (bToObj)); / / object
Conversion methods supported by 3.Javascript:
Eval ('('+ jsonstr +')'); / / you can convert json strings into json objects. Note that you need to wrap a pair of parentheses around json characters
Note: ie8 (compatibility mode), ie7 and ie6 can also use eval () to convert strings to JSON objects, but these methods are not recommended, which is not safe for eval to execute expressions in json strings.
The official conversion method of 4.JSON:
A json.js is provided so that ie8 (compatibility mode), ie7 and ie6 can support JSON objects and their stringify () and parse () methods
You can get this js on the, usually using json2.js now.
2. JSON? String? With? Java? Object conversion
1. Convert the list of java objects to an array of json objects and convert them to strings
JSONArray array=JSONArray.fromObject (list)
String
Jsonstr=array.toString ()
two。 Convert a java object to a json object and convert it to a string
JSONObject object=
JSONObject.fromObject (user)
Log4jInit.ysulogger.debug (object.toString ())
3. Convert JSON strings to JAVA
Object array
JSONArray json=
JSONArray.fromObject (userStr); / / userStr is a json string
List
Users=
(List) JSONArray.toCollection (json, User.class)
4. Convert JSON strings to JAVA
Object
JSONObject
Jsonobject=JSONObject.fromObject (jsonStr)
User user=
(User) JSONObject.toBean (object,User.class)
At this point, I believe you have a deeper understanding of "how jquery converts objects into strings". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.