send request (URL)1.client----------------"service sideSend data (Json/xml)1. xml FormatCommon: plist file, NetEase news, Sina NewsXML documentTag/node Tag name RootTag Value/node value Beijingkey= "1" attribute nodeProperty: key= "1"Property Name: KeyProperty value: "1"*xml data (document) top-down tree structure** Ea
This article is intended to show you how to convert the acquired XML document into a corresponding JSON format string by using C # and then output it to the front of the page for JavaScript code parsing. Perhaps you can directly use JavaScript code to read XML through Ajax,
The difference between XML and JSONIn JavaScript, JSON is a home battle, and its advantages are certainly far superior to XML.or ease of use, JSON is more readable than XML several Changan Street, parsing rules are much simpler. XML
. strategies can registered allowing customization of how particular types is represented as XML.
Security Framework. Fine-control about the unmarshalled types to prevent security issues with manipulated input.
Error messages. When a exception occurs due to malformed XML, detailed diagnostics is provided to help isolate and fix the problem.
alternative output format. The modular design allows other o
information, and the included script tag is executed when the DOM is inserted.?" Script ": Returns plain text JavaScript code. Results are not automatically cached. Unless the "cache" parameter is set. Note: On remote requests (not in the same domain), all POST requests are converted to GET requests. (because the script tag of the DOM will be used to load)?" JSON: Returns the
· ReadabilityThe readability of JSON and XML is comparable. One side is the suggested syntax and the other side is the standard tag format, which makes it difficult to distinguish between the two.· ScalabilityXML is inherently highly scalable, and JSON is also available. There is nothing XML can be extended, and
();}Response.getwriter (). Print (resultjson.tostring ());}
JS Code
function Jsonresponse (originalrequest) {alert (Originalrequest.responsetext);var myobj = OriginalRequest.responseText.evalJSON (true);alert (myobj.name);alert (myobj.age);}using JSONJSON, also known as JavaScript Object notation, is a lightweight syntax for describing data. JSON is elegant because it is a subset of the
The analogy between JSON and XML(1). Advantages and disadvantages of XMLA. Uniform format, in line with the standards;B. Easy to interact with other systems remotely, data sharing is more convenient.A.xml file is large, the file format is complex, the transmission occupies the bandwidth;B. Both the server side and the client need to spend a lot of code to parse the XML
Serialization in. NET is usually in binary or xml format. After ajax emerged, the JSON format is also used, which is rare compared with YAML.
BinaryCannot be directly read. It must be decoded at the binary level;The format is defined by the vendor. When the objects to be represented by a specific application are complex, the format is also complex, such as the office file format;We usually need to fully co
Difference:1. Readability: Basically the same, the readability of XML is better;2. Scalability: all have good extensibility;3. Coding Difficulty: JSON coding is easier;4. Decoding difficulty: The decoding difficulty of JSON is basically 0,xml need to consider child node and parent node;5. Data volume aspect:
XmlAdvantages:One of the big advantages of XML is that it is an extensible format that, when used, is not subject to a predetermined data structure, but is free to define the desired structure as long as the structure remains consistent throughout the document. Another benefit of XML is that it conforms to the DOM standard, as long as the data obtained through AJAX calls can be parsed like ordinary HTML doc
An app communication interface three elements:1. Interface Address: (Http://app.com/api.php?format=xml)2. Interface file: (api.php handles some business logic)3. Interface Communication DataHow the App communicates1.APP sending HTTP requests to the server2. Return data to app after server processingand b/s access different ways:b/S Mode Access Server Page address can be seen in the Address bar and app access to see the address, has been encapsulated.b
As a client, generally from the background of the data passed mainly two, one is the JSON data is an XML format of data for both of these data we need a set of their own analytic methodJson:JSON (JavaScript Object Notation) is a lightweight data interchange format. Easy for people to read and write. JSON is derived fro
, faster read and write, ability to parse using the built-in JavaScript eval () method, use arrays, do not use reserved wordsWhy use JSON? For AJAX applications, JSON is faster and easier to use than XML:using XMLRead the XML document, use the XML DOM to iterate through the
": "Www.weibo.com"}];//ArrayAccess to array: Sites[0].name; return Runoob
Json.parse ()
Converts a string into a JavaScript object.JSON cannot store Date objects and needs to be converted to strings for storagePlease visit the website for more details
Json.stringify ()
Converts a JavaScript object into a string.JSON cannot store Date objects.Json.stringify () converts all dates to string
When the data structure is simple enough for a two-dimensional table to describe the format,
The comma interval represents the column, \ r \ n represents the row, and the first row is the corresponding property name.
Like
ColName1, ColName2, ColName3
1, "title", "Http://ss.ss.com/ss"
2, "title", "Http://ss.ss.com/ss"
3, "title", "Http://ss.ss.com/ss"
In this way, remove the redundant attribute tags such as xml,
When writing Ajax, it is often necessary to parse a string returned from the server. Here we will briefly introduce two formats of characters returned by the server and the parsing methods of Js for them.
I. JSON
JavaScript Object Notation (JavaScript Object Notation) is a string that is combined by declaring objects in Js.JS can define objects as follows:
XML (extensible Markup Language)Definition: An extensible, markup languageXML has a wealth of coding tools, such as dom4j, Jdom, and so on.JSON (JavaScript Object Notation)Definition: A lightweight format for data interchangeJSON also has the tools provided by json.org, but JSON is much easier to encode than XML, and e
). These structures can be nested.
A string is a collection of any number of Unicode characters enclosed by double quotes. It is escaped using a backslash. A character (character) is a separate string (character string ). A string is very similar to a C or Java string.
Although a JSON string is called a string, its full process is called JavaScript Object Notation-Java
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.