读取JSON文件并 排序,分组,
读取.json文件
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;
}
返回.json文件
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排序 a.properties[field]根据排序的ID
var JsonSort = p.sort(function (a, b) { return a.properties[field] > b.properties[field] ? 1 : -1; });
----------------------------------------JSON分组
///json 数组 根据某一字段相同名称进行分组
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] = "什么都没有";
}
if (!map[ai.properties[str]]) { //判断没有出现这个字段的数组
dest.push({
id:ai.properties[str],
data: [ai]
});
map[ai.properties[str]] = ai; ///总的分组
} else { ///已经出现过的数组进行循环遍历到已经出现的数组中
for (var j = 0; j < dest.length; j++) {
var dj = dest[j];
///把相同的元素添加到data里面去
if (dj.id == ai.properties[str]) {
dj.data.push(ai);
break;
}
}
}
} console.log(dest)
读取JSON文件并 排序,分组,的更多相关文章
- jquery无法读取json文件问题
jquery无法读取json文件,如:user.json文件无法读取.把user.json文件的后缀名修改为aspx,文件内容不变,则可以读取~ 原理不懂!~~
- Unity 用C#脚本读取JSON文件数据
读取JSON文件数据网上有很多方法吗,这里采用SimpleJSON,关于SimpleJSON的介绍参考以下链接:http://wiki.unity3d.com/index.php/SimpleJSON ...
- cocos2d-x 读取 json 文件并用 jsoncpp 做解析
一码胜万言(请看注释) CclUtil.h // // CclUtil.h // PracticeDemo // // Created by kodeyang on 8/1/13. // // #if ...
- jQuery读取json文件,实现省市区/县(国标)三级联动
最近做一个微信项目,需要用户填写所在的省市区/县,决定使用jQuery读取json文件来实现省市区/县的联动. 其实很简单,jQuery文档也有详细解释: 代码如下: html <table w ...
- jqery ajax读取json文件
json文件数据 [ {"name":"哈哈··","email":"邮箱01","gender": ...
- spring注解读取json文件
开发时候在接口没有提供的时候,可以用json文件提前模拟接口数据 1.service层 package com.syp.spring.service; import java.io.File; imp ...
- Android - 读取JSON文件数据
Android读取JSON文件数据 JSON - JavaScript Object Notation 是一种存储和交换文本信息的语法. JSON对象在花括号中书写.用逗号来分隔值. JSON数组在方 ...
- Asp.Net MVC 读取json文件
有些系统上面的配置可以做成config里面的appsetting.这里要求写在json文件里面. 首先 添加命名空间 using Newtonsoft.Json; using System.IO; u ...
- Python json 读取 json 文件并转为 dict
Python json 读取 json 文件并转为 dict 在 D 盘 新建 test.json: { "test": "测试\n换行", "dic ...
随机推荐
- tp5.1升级
# php think version v5.1.23 # composer update Loading composer repositories with package information ...
- angular2 自定义双向绑定属性
import { Component, OnInit, Output, Input, EventEmitter } from '@angular/core'; @Component({ selecto ...
- jmeter-01 JMeter HTTP测试的各元件功能演示示例
最小的测试将包括测试计划,线程组和一个或多个采样器. Jmeter HTTP测试的各元件演示示例 功能逻辑:wap官网(a.4399sy.com.hk),每个用户登录一次,发帖2次,发帖成功后注销退出 ...
- 获取url参数,替换特殊字符
function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)( ...
- HDU 5687 字典树入门
Problem C Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- magento: Your web server is configured incorrectly. As a result, configuration files with sensitive information are accessible from the outside 解决方案
在linux(以UBUNTU, CENTOS为例)下安装完成magento时,在进入后台时, 有些童鞋可能会发现有如下的提示: Your web server is configured incorr ...
- [转载]各种java生成word解决方案的优缺点对比
解决方案 优点 缺点 Jacob 功能强大 直接调用VBA接口,程序异常复杂:服务器必须是:windows系统+安装Office:服务器端自动化com接口容易产生死进程造成服务器宕机 Apache P ...
- dropload.js 上滑加载,下拉刷新
https://github.com/ximan/dropload dropload a javascript implementation of pull to refresh and up to ...
- ExcelHelper.cs
using System; using System.IO; using System.Data; using System.Collections; using System.Data.OleDb; ...
- Linux服务器上安装tomcat
安装软件 : apache-tomcat-9.0.0.M1.tar.gz(下载地址http://tomcat.apache.org/) 步骤一 Tomcat是其中一个开源的且免费的java Web服务 ...