如何读取 Json 格式文件
Json 源文件代码:
[
{
"Id": "0",
"Name": "书籍",
"Detail": [
{
"ParentName": "书籍",
"Name": "苹果",
"URL": "wwww.baidu.com"
},
{
"ParentName": "书籍",
"Name": "香蕉",
"URL": "wwww.baidu.com"
}
]
},
{
"Id": "1",
"Name": "水果",
"Detail": [
{
"ParentName": "水果",
"Name": "苹果",
"URL": "wwww.sohu.com"
},
{
"ParentName": "水果",
"Name": "香蕉",
"URL": "wwww.sohu.com"
}
]
} ]
C# 读取文件内容:
var jsonPath = Server.MapPath("~/Scripts/Products.json");
string config = File.ReadAllText(jsonPath);
List<ProductInfo> CertConfigs = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProductInfo>>(config);
构造类:
public class ProductInfo
{
public string Id { get; set; }
public string Name { get; set; }
public List<ProductDetail> Detail { get; set; }
}
public class ProductDetail
{
public string ParentName { get; set; }
public string Name { get; set; }
public string URL { get; set; }
}
Js 读取源文件代码:
var option = '';
$.getJSON("Scripts/Products.json", function (jsonData) {
$.each(jsonData, function (index, detailInfo) {
option1 += "<option id=" + detailInfo.id + ">" + detailInfo.name + "</option>";
});
$("#jsonProduct").append(option1);
$("#jsonProduct").bind("change", function () {
//选择触发事件
})
});
H5代码
<select id="jsonProduct"></select>
如何读取 Json 格式文件的更多相关文章
- pyhton读取json格式的气象数据
原文关于读取pm25.in气象数据的pyhton方法,以及浅析python json的应用 以pm25.in网站数据为例. 1.方法介绍 首先感谢pm25.in提供了优质的空气污染数据,为他们的辛勤劳 ...
- Android读取JSON格式数据
Android读取JSON格式数据 1. 何为JSON? JSON,全称为JavaScript Object Notation,意为JavaScript对象表示法. JSON 是轻量级的文本数据交换格 ...
- java导出json格式文件
生成json文件代码: import java.io.File; import java.io.FileWriter; import java.io.Writer; public class Crea ...
- 简单创建json格式文件
简单创建json格式文件 核心就两点: addProperty 添加属性(也就是加键值对) add是添加 另外的object对象 然后直接toString()输出 核心代码如下; public cla ...
- VS调试时JSON格式文件无法加载
VS调试时JSON格式文件无法加载 报错: 解决:在项目中的web.config中进行配置,configuration节中添加以下部份: <system.webServer> <st ...
- 使用jsp读取TXT格式文件
<%@page import="java.io.BufferedReader"%> <%@page import="java.io.FileReader ...
- python 生成json格式文件,并存储到手机上
上代码 #!/usr/bin/env python # -*- encoding: utf-8 -*- import json import os import random "" ...
- .net core读取json格式的配置文件
在.Net Framework中,配置文件一般采用的是XML格式的,.NET Framework提供了专门的ConfigurationManager来读取配置文件的内容,.net core中推荐使用j ...
- 读取siftgeo格式文件的matlab程序
% This function reads a siftgeo binary file %读取siftgeo格式的二进制文件 % % Usage: [v, meta] = siftgeo_read ( ...
随机推荐
- Authors and instutes in MCT
Authors and instutes in MCT Table of Contents 1. Authors and Institutes 1.1. Industry 1 Authors and ...
- PAT 1125 Chain the Ropes
Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...
- 日期工具类 DateTools
为了跟其他日期工具类进行区分起名字DateTools public class DateTools { /** The DAT e_ forma t1. */ public static String ...
- @Value取值为NULL的解决方案------https://blog.csdn.net/zzmlake/article/details/54946346
@Value取值为NULL的解决方案 https://blog.csdn.net/zzmlake/article/details/54946346
- Codeforces Round #234 (Div. 2)
A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input st ...
- Stealing Harry Potter's Precious BFS+DFS
Problem Description Harry Potter has some precious. For example, his invisible robe, his wand and hi ...
- Nginx源码分析:3张图看懂启动及进程工作原理
编者按:高可用架构分享及传播在架构领域具有典型意义的文章,本文由陈科在高可用架构群分享.转载请注明来自高可用架构公众号「ArchNotes」. 导读:很多工程师及架构师都希望了解及掌握高性能服务器 ...
- yum 源本地化 (two)
之前写过一个yum源本地化的文章. 后来发现那个方法有些缺陷, yum install --downloadonly --downloaddir=/tmp/atomicdownload memcach ...
- 小议C#错误调试和异常处理
在程序设计中不可避免地会出现各种各样的错误,在编写代码时须要尽量避免. 在处理错误时,首先应该分析错 误的类型,找出出错的原因才干解决错误. 错误的分类 watermark/2/text/aHR0cD ...
- ObjectiveC开发教程--字符串的连接
NSString *type = @"hello"; NSString *subtype = @"good"; NSString *typesub = [NSS ...