在本文中,我们将详细介绍一个好用的json文件本地查看工具-JSONviewer的各个方面,并为您提供关于json文件查看器的相关解答,同时,我们也将为您带来关于C#NEWTONSOFT.JSON读取
在本文中,我们将详细介绍一个好用的json文件本地查看工具 - JSON viewer的各个方面,并为您提供关于json文件查看器的相关解答,同时,我们也将为您带来关于C# NEWTONSOFT.JSON读取json文件、C# 使用Newtonsoft.Json读写Json文件、HiJson —— 不错的 json 查看工具、iPhone上的JSON(三)JSON+UITableView的有用知识。
本文目录一览:- 一个好用的json文件本地查看工具 - JSON viewer(json文件查看器)
- C# NEWTONSOFT.JSON读取json文件
- C# 使用Newtonsoft.Json读写Json文件
- HiJson —— 不错的 json 查看工具
- iPhone上的JSON(三)JSON+UITableView
一个好用的json文件本地查看工具 - JSON viewer(json文件查看器)
我在公司从事云原生应用的开发工作,每天开发的微服务需要经常和返回json数据格式的Restful API打交道,我不喜欢用各种在线的json数据查看工具,因为json数据一旦超过一定的规模比如10MB之后,这些在线工具响应速度就很慢了。
本人不太喜欢各种在线的json文件查看工具,还是更偏爱能本地离线使用的工具,于是在bing上找了一个:JSON viewer
主界面如下:
能在tree和Source两种显示模式间进行切换:
提供一些简单的小工具,比如json字符串的validation和格式化:
就算不注册,也不影响使用,因为试用期长达14000多年
更多Jerry的原创文章,尽在:“汪子熙”:
本文同步分享在 博客“汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
C# NEWTONSOFT.JSON读取json文件
public static void Readjson()
{
string jsonfile = "D://tsconfig1.json";
using (System.IO.StreamReader file = System.IO.File.OpenText(jsonfile))
{
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o = (JObject)JToken.ReadFrom(reader);
string a = o["lotname"].ToString();
var b = o["other"];
var c = b["lotaddress"];
var d = o["devices"];
foreach(JObject e in d)
{
var deviceID = e["deviceID"];
var name = e["name"];
var IP = e["IP"];
}
}
}
}
tsconfig1.json文件内容
{
"lotname": "停车系统",
"devices": [
{
"deviceID": "EI1001",
"name": "东道进口相机",
"type": "进口",
"IP": "192.168.1.100"
},
{
"deviceID": "EI1002",
"name": "东道进口语音屏",
"type": "进口",
"IP": "192.168.1.102"
},
{
"deviceID": "EO1003",
"name": "东道出口相机",
"type": "出口",
"IP": "192.168.1.103"
},
{
"deviceID": "EO1004",
"name": "东道出口语音屏",
"type": "出口",
"IP": "192.168.1.104"
}
],
"other": { "lotname": "wz001", "lotaddress": "wenzhou" }
}
注意:记事本另存为 以上内容时编码选择 U-TF8
C# 使用Newtonsoft.Json读写Json文件
{
"CAN": false,
"AccCode": 4294901856,
"Id": 768,
"BPointMove": true,
"L_BPointMoveDelay": "600",
"R_BPointMoveDelay": "1000"
}

1.Read

try
{
using (StreamReader file = File.OpenText("config.json"))
{
using( JsonTextReader reader = new JsonTextReader(file))
{
JObject jsonObject = (JObject)JToken.ReadFrom(reader);
CAN_Communication = (bool) jsonObject["CAN"];
AccCode = (uint) jsonObject["AccCode"];
Id = (uint) jsonObject["Id"];
// Configure Json
BPointMove = (bool)jsonObject["BPointMove"];
_classLeft.DelayBPointMove = (int)jsonObject["L_BPointMoveDelay"];
_classRight.DelayBPointMove = (int)jsonObject["R_BPointMoveDelay"];
file.Close();
}
}
}
catch
{
//MessageBox.Show("CAN卡配置有误!");
}

2.Write

try
{
string json = File.ReadAllText("config.json");
dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
jsonObj["L_BPointMoveDelay"] = LBPointdelay.ToString();
string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText("config.json", output);
}
catch { }

HiJson —— 不错的 json 查看工具
OSC 请你来轰趴啦!1028 苏州源创会,一起寻宝 AI 时代
iPhone上的JSON(三)JSON+UITableView
既然JSON这么好,它怎么和UITableView结合使用呢?
首先看看我们的JSON文件吧:
{ "老张家":["大张","二张","三张"], "老李家":["大李","二李"] }
完成的作品是这样样子的~~(点击放大阿~~)
好,开始打代码吧。
1,首先copy JSON库到当前的Project里面。
2,建立一个数据源类。我给它起名叫MyDataSource, 看看里面都有什么吧:
@interface MyDataSource : NSObject {} + (id)dataSource;@end #import "JSON.h" @implementation MyDataSource+ (id)dataSource{ NSString* JSONString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"] encoding:NSUTF8StringEncoding error:nil]; return [JSONString JSONValue];} @end
里面非常简单,只有一个类方法dataSource。在其中我们读取json文件的内容到一个NSString中,并用JSON框架来解读成一个 NSDictionary,返回值为id。因为虽然大多的时候最外的对象都为NSDictionary,但是出于严谨,万一是NSArray不就崩溃了。所以使用id,这样其实就有再次可以用的特性了。
3,建立一个UITableViewController, 然后作适当的设置:
#import "MyTableViewController.h" #import "MyDataSource.h" @implementation MyTableViewController - (id)initWithStyle:(UITableViewStyle)style{ if (self = [super initWithStyle:style]) { myData = [[MyDataSource dataSource] retain]; //在这里我们初始化myData,其实就是一个id对象 //传入由MyDataSource解析出的NSDictionary } return self;} #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [myData count]; //有多少个section,也就是“几家” } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[myData valueForKey:[[myData allKeys] objectAtIndex:section]] count];//这里我们需要告诉UITableViewController每个section里面有几个,也就是“一家里面有几口人” } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } //上面的东西都是重复白给的,平时没事不用想为什么,照抄就可以了 cell.textLabel.text = [[myData valueForKey:[[myData allKeys] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; //这句看上去复杂,但是其实不过是在特定section里面找到对应的array, //然后在array中找到indexPath.row所在的内容 return cell;} - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return [[myData allKeys] objectAtIndex:section];//这里设置对应section的名字,很简单allKey返回所有的键值为一个array,也就是“张家”,“李家” //然后用objectAtIndex: 来找出究竟是哪一个就可以了! } - (void)dealloc { [myData release]; //“我们是runtime的好市民”...release就好Alan...... [super dealloc];} @end
4,在主程序代理 xxxAppDelegate 里面初始化这个UITableViewController然后添加它的view到window的subview中就OK拉!
5,编译运行,没有错误就万事大吉!大吉!
阿弥陀佛,祝各位愉快~
关于一个好用的json文件本地查看工具 - JSON viewer和json文件查看器的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于C# NEWTONSOFT.JSON读取json文件、C# 使用Newtonsoft.Json读写Json文件、HiJson —— 不错的 json 查看工具、iPhone上的JSON(三)JSON+UITableView的相关知识,请在本站寻找。
本文标签: