Files
Sprout-Farm/Server/JsonEdit/example_formats.md

65 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# JSON格式化示例
以下展示三种不同的JSON格式化效果
## 原始数据
```json
{"小麦":{"花费":120,"收益":100,"品质":"普通"},"稻谷":{"花费":100,"收益":120,"品质":"普通"}}
```
## 1. 标准格式化2空格缩进
```json
{
"小麦": {
"花费": 120,
"收益": 100,
"品质": "普通"
},
"稻谷": {
"花费": 100,
"收益": 120,
"品质": "普通"
}
}
```
## 2. 最小化(压缩)
```json
{"小麦":{"花费":120,"收益":100,"品质":"普通"},"稻谷":{"花费":100,"收益":120,"品质":"普通"}}
```
## 3. 一行化(一个对象一行)
```json
{
"小麦": {"花费":120,"收益":100,"品质":"普通"},
"稻谷": {"花费":100,"收益":120,"品质":"普通"}
}
```
## 使用场景
- **标准格式化**: 适合阅读和编辑,开发时使用
- **最小化**: 适合网络传输,节省带宽
- **一行化**: 适合比较不同对象,每行一个对象便于查看差异
## 批量添加属性示例
添加键名: `能否购买`, 键值: `true`
### 结果:
```json
{
"小麦": {
"花费": 120,
"收益": 100,
"品质": "普通",
"能否购买": true
},
"稻谷": {
"花费": 100,
"收益": 120,
"品质": "普通",
"能否购买": true
}
}
```