Read the. json file
public string Getfilejson (string filepath)
{
String json = string. Empty;
using (FileStream fs = new FileStream (filepath, FileMode.Open, System.IO.FileAccess.Read, Fileshare.readwrite))
{
using (StreamReader sr = new StreamReader (FS, encoding.getencoding ("gb2312"))
{
JSON = Sr. ReadToEnd (). ToString ();
}
}
return JSON;
}
return. json file
Public ActionResult Gridpagelistjson ()
{
Try
{
string filepath = Server.MapPath ("~/views/orderinfokj/json1.json");
String json = Getfilejson (filepath);
Return Content (JSON);
}
catch (Exception ex)
{
return null;
}
}
--------------------------------------JSON sort A.properties[field] based on the sorted ID
var jsonsort = P.sort (function (A, b) {return A.properties[field] > B.properties[field]? 1:-1;});
----------------------------------------JSON grouping
JSON arrays are grouped according to the same name of a field
var arr = eval ("(" + da + ")"). Features;
var map = {},
Dest = [];
for (var i = 0; i < arr.length; i++) {
var ai = arr[i];
if (ai.properties[str] = = "" | | AI.PROPERTIES[STR] = = "0" | | AI.PROPERTIES[STR] = = NULL | | AI.PROPERTIES[STR] = = 0 | | AI.PROPERTIES[STR] = = Undefined | | AI.PROPERTIES[STR] = = False) {
AI.PROPERTIES[STR] = "nothing";
}
if (!map[ai.properties[str]]) {//To determine that no array of this field appears
Dest.push ({
ID:AI.PROPERTIES[STR],
Data: [AI]
});
MAP[AI.PROPERTIES[STR]] = AI; Total grouping
} else {////An array that has already occurred loops through the array that has occurred
for (var j = 0; J < Dest.length; J + +) {
var DJ = Dest[j];
Add the same elements to the data.
if (dj.id = = Ai.properties[str]) {
Dj.data.push (AI);
Break
}
}
}
} console.log (dest)
Read JSON files and sort, group,