如何将JSON用于关系类型数据-最好只是重复数据? [英] How do I use JSON for relational type data - best to just repeat data?

查看:80
本文介绍了如何将JSON用于关系类型数据-最好只是重复数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建JSON作为小型汽车数据库。如果要使用MySQL,我将创建一个Maker表,以免重复每辆汽车的maker和maker属性。在JSON中执行此操作的最佳方法是什么?例如,如果我具有以下制造商属性:

I would like to create JSON to act as a small database of cars. If I were to use MySQL, I would create a Maker table so as not to repeat the makers and maker attributes for every single car. What is the best way to do this in JSON? for instance, if I have the following attributes for maker:

名称:福特,
网址: ford.com,
成立:某年
等...

"Name": "Ford", "URL": "ford.com", "Founded" : "some year" etc...

然后是汽车列表
名称:野马 ,
第一年:某年,
制造商:福特
制造商网址: ford.com

and then the car list "Name": "Mustang", "first year" : "some year", "maker" : "Ford" "maker URL" :"ford.com"

我不想为每辆福特汽车重复制造商属性。我应该有两个JSON文件,并通过制造商ID或唯一的制造商名称将它们链接在一起吗?还是我应该只允许每辆福特汽车重复制造商属性?我专门在Objective-C / iOS中执行此操作,因此可以在iPhone上使用数据。我将JSON提取到数组中进行解析和查看。

I don't want to repeat the maker attributes for every ford car. Should I have two JSON files and link them together by a maker id or unique maker name? or should I just allow the maker attributes to repeat for every ford car? I'm specifically doing this in Objective-C/iOS so I can use the data on an iPhone. I will pull the JSON in to an Array for parsing and viewing.

推荐答案

为什么不使用SQLLite核心数据并创建您将在mySQL中使用的相同表?
如果您真的想坚持使用JSON,那么正确的分析器取决于对
而言重要的内容。例如节省空间?易于更新(如果福特URL更改为cars.ford会怎样?)?更少的读取访问?等等

Why not use core data which is SQLLite and create the same tables you would use in mySQL ? If you really want to stick with JSON, then the "right" anser depends on what is important to you. e.g saving space ? ease of update (what if the Ford URL changes to cars.ford) ? fewer read accesses ? etc

这篇关于如何将JSON用于关系类型数据-最好只是重复数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆