如何在iOS的动态解析JSON [英] How to parse JSON dynamically in iOS

查看:430
本文介绍了如何在iOS的动态解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用第三方服务,它提供了一个JS文件。
JS文件启动一个http请求并获得json.We解析的JSON和得到了我们想要内容,但JSON格式总是变化。

We used a third party service and it provides a JS file. The js file launches an http request and get a json.We parsed the json and got the content we wanted but the json format always changes.

有没有一种方法来解析JSON但不更新我们的应用程序?

Is there a way to parse the json but do not update our app?

推荐答案

这听起来很可怕愚蠢的不断变化的模式,但不管怎么说,也许你可以尝试在翻译了最新架构的关键字到一个你的应用程序的云某处有一个清单理解?

It sounds awful stupid to constantly change schemas, but anyway, maybe you could try having a manifest somewhere in the cloud that translates the latest schema keywords into one your app understands?

基本上,我presume,在JSON的信息是相似的(否则就没有任何意义可言),只有关键字改变。你可以有一个JSON你不断地更新转化的应用到由Web服务使用的最新的一个使用的关键字。

Basically, I presume that the info in the JSON is similar (otherwise it wouldn't make sense at all) and only the keywords change. You could have a JSON you constantly update that translates the keywords used in the app into the newest one used by the webservice.

因此​​,一个例子是这样的。想象一下,这是你用来开发应用程序时的格式(这是一个应用程序期待)。​​

So an example would look like this. Imagine this is the format you are used to when developing the app (this is the one app expects).

{
    "name" : "Henri",
    "title" : "iOS Developer"
}

现在如果web服务改变了它的架构和返回这样的事情

Now if the webservice changes it's schema and returns something like this

{
    "key1" : "Henri",
    "key2" : "iOS Developer"
}

您应该有它转换这样一个的manifest.json

You should have a manifest.json which translates it like this

{
    "name" : "key1",
    "title" : "key2"
}

我希望你能在那里我这个打算,基本上可以翻译转移到云中,使您能够保持最新的应用程序,同时保持相同的机会。所以在翻译后加载您可以访问这样的数据

I hope you get where I'm going with this, basically you can shift the translation to the cloud, giving you the chance to keep it up to date while app remains the same. So after loading in the translation you can access the data like this

NSString *name = [actualJSON objectForKey: [manifestJSON objectForKey: @"name"]];

这篇关于如何在iOS的动态解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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