最近,我们的团队将为我们现有的网站开发移动(iphone,android平台)应用程序,让用户可以使用该应用程序通过应用程序更容易阅读我们的内容。
但是我们的团队在API返回的JSON模式中有不同的视图,下面是示例响应。
架构类型1:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": {
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
"user": {
"user_id": 1,
"name": "Hello World",
"email": "helloworld@hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": {
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
},
"user": {
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby@hello.com",
"user_permalink": "http://sample.com/user/2"
},
"post_ts": "2012-12-01 18:15:00T0800"
}
]
}
}
架构类型2:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": 100,
"user": 1,
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": 101,
"user": 2,
"post_ts": "2012-12-01 18:15:00T0800"
}
],
"category": [
{
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
{
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
}
],
"user": [
{
"user_id": 1,
"name": "Hello World",
"email": "helloworld@hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
{
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby@hello.com",
"user_permalink": "http://sample.com/user/Hello_baby"
}
]
}
}
一些开发人员声称如果使用架构类型2,
我不知道架构类型2是否确实增强了。因为我读了这么多API文档,所以从未见过这种类型的架构设计。对我来说,它看起来像一个关系数据库。所以我几乎没有问题,因为我没有设计Web服务API的经验。
谢谢你。
答案 0 :(得分:0)
当我为android做这样的应用程序时,我只解析一个JSON并将其放入数据库中。后来我使用ContentProvider来访问它。在您的情况下您可以使用第二个架构,但没有用户,类别部分。使用延迟加载,但它将是一个很好的解决方案,以防类别和用户经常重复。