JSON contains two data structures, one similar to a hash table and the other similar to an array.
To put it simply, it is an alternative solution for data transmission using XML, with fewer bytes passed. The transmission process is essentially a string wrapped in {} or [].CodeShort interpreter. {} Corresponds to object, and [] corresponds to array. You can perform reverse operations on the Code side. Currently, many Ajax-based applications obtain data on the server, generate JSON, upload the data to the client, and then render the interface on the client ..
A string in a specific format.
OK. After learning about the JSON structure, let's take a look at the $. getjson () method in jquery. This method has three parameters: $. getjson (string URL, hash Params, function callback ). Here, the URL is the request address for obtaining JSON structure data, that is, accessing this address will get a piece of JSON structure text (which is encapsulated by jquery here, this text is obtained through the responsetext attribute of the request object ). Params is a parameter sent to the URL service. The server can respond to these parameters. The parameter structure is similar to the JSON structure, and is similar to the structure of "{key1: value1, key2: value2. Callback is the callback function, that is, function (JSON) {// code...}, which is used for client processing. In the callback function, the JSON parameter is an object constructed by the JSON structure text requested from the URL. JSON parameters are easy to use. They are a hash table object and can be used in JSON. Key Mode to define attributes. For example, if we input the JSON structure of the preceding example, we can use JSON. Addresses [0] to obtain the first value of addresses.
JSON is not mysterious. To put it bluntly, it is actually a hash table structure and can be directly used in Javascript, which is very convenient.
//-------------------------------------------------------
Google"Access to restricted URI denied", Found the problemCross-DomainAbove, readJqueryFrom1.2Start using versionJquery. getjson (URL, [data], [callback])For cross-origin submission, refer to the following:
As of jquery 1.2, you can load JSON data located on another domain if you specify a jsonp callback, which can be done like so: "myurl? Callback =? ". Jquery automatically replaces? With the correct method name to call, calling your specified callback.
Read the aboveJsonpAlmost nothing, according to the requirements I added? Callback =? ",I still cannot retrieve any data.JSThe Code is as follows:
$. Getjson ( " Fetchauthenticationtickethandler. ashx? Jsoncallback =? " ,
Function(Data ){
$ ("# Divheaderlink"Pai.html (data. Name );
});
However, data is always unavailable and the breakpoint is set Data. Name A row that has never been executed. So we started to look Jsoncallback = ?, I found that this is actually a value, but I have never Handle (It's because you don't know how it works. Handle , Google For a long time, almost no direct use was found Ashx To process Remote JSON Example), but I found an articleArticleIs a special introduction Jquery Ajax As mentioned above Jsoncallback The value is passed back. Ashx After a few changes, the following code is finally debugged:
<% @ Webhandler Language = " C # " Class = " Handler " %>
UsingSystem;
UsingSystem. Collections. Generic;
UsingSystem. Web;
UsingSystem. Web. Services;
UsingSystem. net. JSON;
/// <Summary>
/// Summary Description for $ codebehindclassname $
/// </Summary>
[WebService (namespace = " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
Public Class Handler: ihttphandler
{
Public VoidProcessrequest (httpcontext context)
{
Context. response. contenttype= "Text/plain";
Jsonobjectcollection collection = New Jsonobjectcollection ();
Collection. Add ( New Jsonstringvalue ( " URL " , " Http: // 124.172.245.164: 999/ftpimage_speinfoimage/2009/12/1/20091201173357_w200_h80_t1_i1.jpg " ));
Collection. Add ( New Jsonstringvalue ( " Value " , " Ftpimage_speinfoimage/2009/12/1/20091201173357_w200_h80_t1_i1_jpg " ));
String Str = Context. Request. querystring [ " Jsoncallback " ] + " ( " + Collection + " ) " ;
Context. response. Write (STR );
}
Public BoolIsreusable
{
Get
{
Return False;
}
}
}
Where, Jsonobjectcollection Class to be referenced Using System.Net.JSON; Yes JSON One recommended on the official website DLL , It feels good. The advantage of using this function is that Html Code processing, because JSON Data is transmitted through "", Html It also contains "". If you spell it manually, it will be very troublesome.
ashx
Jsonxxxxxxxxxxxxxx?Where JsonxxxxxxxxxxxxxxYesContext.Request.Querystring["Jsoncallback"].
---------------------
The Sina survey combines the bar chart displayed in JSON format .. Survey.rar
/Files/fooo/survey.rar/files/fooo/etwebsite.rar
E fake travel combined with JSON to display the loading status when the image is loaded...
/Files/fooo/etwebsite.rar
Simple Example of getjson:
/Files/fooo/jquerygetjsondemo.rar