In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article to share with you is about JavaScript object symbol JSON introduction is what kind of, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some gains, not much to say, follow Xiaobian to see it.
introduced
One of the bigger challenges programmers/developers/architects have faced for some time is how to transfer data from one system to another without considering hardware or software requirements. In the meantime, we've seen a lot of technology trying to make this requirement as simple as possible, and now we've finally implemented it with the help of JSON.
JSON is an acronym for JavaScript Object Notation. Douglas Crockford originally specified the JSON format in the early 2000s. The characteristics of JSON are as follows:
JSON data is easier for humans to read than XML data, which is also used to transfer from one system to another.
It is a lightweight data exchange format.
It follows an open standard format for transferring data objects that store information in a key-value pair pattern.
It is a language-independent data format.
JSON makes it easier to map to object-oriented systems.
Files containing JSON data have a ". Extensions that can be read by any programming language.
Typical JSON looks like this:
Examples 1
{ "Name":"Jojo", "Age": 23 }
explain
"Name" is the key and "Jojo" is the value of the key. Again,"age" is the key, and 23 is the value of the key. If you notice that the value 23 doesn't have double quotes, it proves that JSON supports multiple data types, one of which is numbers. In addition to numbers and strings, other data types supported by JSON are:
boolean
array
Numbers (integer, floating point, fixed point)
object
spaces
Null
The example above contains details for only one object. If we plan to have an array of objects, then the storage will look like this:
Example 2
{ "Employees":[ {"Name":"PopatLal", "Age":25}, {"Name":"Santa Singh", "Age":27}, {"Name":"Banta Singh", "Age":28}, {"Name":"SohanLal", "Age":25}, ] }
In Example 2, we have an array of objects named Employees that contains two components, Name and Age.
Now, the bigger problem we noticed was how to display JSON information on web pages using ASP.NET MVC 4. Let's take a step by step look at how to use the same method.
We chose a basic template for this sample application, and Solution Explorer looks like this:
Now we are creating a very simple application whose purpose is to print a welcome message that says "Welcome JSON." To do this, we'll add an MVC controller and a method that returns JSONResult. The code is as follows:
public JsonResultWelcomeMessage() { String message = "Welcome to JSON"; returnJson(message, JsonRequestBehavior.AllowGet); }
When you run this program, you will get the following output:
This code now proves that we can view JSON data, and now we need to use it on HTML pages, so we need to create a view for it.
Under DemoController, we write an ActionResult method called Index that returns a view of the same name, Index.cshtml.
publicActionResult Index() { return View(); }
HTML code in Index.cshtml looks something like this:
@{ Layout = null; } Index
The output of the above code looks like this:
Now, in order to execute the JSON method and print the message within a given box, we must use JQuery, where the "getJSON" method is called, and where the "WelcomeMessage" method is called.
The code is as follows:
$(document).ready(function() { $("#btn1").click(function() { vardivObj = $("#messagediv"); $.getJSON("/Demo/WelcomeMessage/", null, function(data) { divObj.append("" + data + ""); }); }); });
When you click the button, the output looks like this:
The above is how the introduction of JavaScript object symbol JSON is, Xiaobian believes that some knowledge points may be what we will see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.