iPhone:如何以编程方式创建 json 文件并将从 Sqlite 数据库获取的数据插入其中?
我想从我的 Sqlite 数据库获取数据并将其放入这个 JSON 文件中。
如何创建 json 文件并将从数据库获取的数据插入到 JSON 文件中?
我想要这种格式的 JSON 文件中的数据:
{
"data": [
{
"data": [
null,
null,
30,
45,
69,
70,
65
],
"title": "title5"
},
{
"data": [
null,
5,
10,
15,
22,
30
],
"title": "title4"
},
{
"data": [
40,
55,
],
"title": "title3"
},
{
"data": [
null,
89,
90,
85
],
"title": "title2"
},
{
"data": [
66,
77,
55,
33,
50,
-6,
-8
],
"title": "title1"
}
],
"x_labels": [
6,
7,
8,
9,
10,
11,
12
]
}
我该怎么做?
I want to get data from my Sqlite database and put it into this JSON file.
How can I create a json file and insert the data obtained from my database into the JSON file?
I want data in JSON file in this format:
{
"data": [
{
"data": [
null,
null,
30,
45,
69,
70,
65
],
"title": "title5"
},
{
"data": [
null,
5,
10,
15,
22,
30
],
"title": "title4"
},
{
"data": [
40,
55,
],
"title": "title3"
},
{
"data": [
null,
89,
90,
85
],
"title": "title2"
},
{
"data": [
66,
77,
55,
33,
50,
-6,
-8
],
"title": "title1"
}
],
"x_labels": [
6,
7,
8,
9,
10,
11,
12
]
}
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建 Obj C 对象从 sqlite 数据库读取数据。假设
您可以从对象创建 JSON 字符串,
我不确定它是否直接适用于数组,如果不能,请将您的 dataArray 封装在 anotherObject 中,然后将该对象发送给此 JSON 编写器。
将 JSON 字符串写入文件。
Create Obj C object reading data from your sqlite database. Say
proxyForJson
method, since its a user defined object.You can make a JSON string from an object ,
I am not sure if it works directly for array, if not, encapsulate your dataArray in anotherObject, and send that object to this JSON writer.
Write the JSON string to a file.
为了创建 json 输出,您可以首先获取某些数组、plist 或字典等中的 sqlite 数据,然后使用函数 JSONRepresentation 来显示相同的 JSON 输出,这里有一个示例代码,可能会帮助您
确保您正在导入 JSON 库。
In order to create a json output what you can do is first get the sqlite data in some array or plist or dictionary etc, then use the function JSONRepresentation to display the JSON output for the same, here's a sample code that might help you
Make sure that you are importing the JSON libraries.