如何在Objective-C中从HTML中读取JSON-LD数据? [英] How to read JSON-LD data from HTML in Objective-C?
问题描述
我正在创建一个从服务器下载HTML文件的应用程序。我将该文件存储在本地存储中以供离线使用。我需要解析该文件中的数据。我可以通过解析HTML标签来实现,但我想制作标准方式,因此 JSON-LD 是使用HTML5的好方法。因此,只要HTML结构发生变化,我就不必更新代码。
I am creating one app that downloads HTML file from server. I am storing that file in local storage for offline usage. I have requirement to parse data from that file. I can do it by parsing the HTML tags, but I want to make is standard way hence JSON-LD is a good way to do it using HTML5. So anytime the HTML structure changes, I would not have to update code.
我想从Objective-C中的HTML文件中读取JSON-LD数据。我用谷歌搜索但没有找到任何漂亮的方式来阅读它。
I want to read JSON-LD data from HTML file in Objective-C. I googled it but not found any pretty way to read it.
我是否必须以同样的方式阅读它,比如从文件中读取HTML字符串?任何人都可以指导我,如果有任何具体的方法吗?
Should I have to read it same way like reading HTML string from file? Can anyone please guide me, if there is any specific way to do it?
推荐答案
我从HTML解析了JSON-LD模型文件使用以下方式,
I have parsed JSON-LD model from HTML file using following way,
-
获取任何XMLParser / HTMLParser字典。 (我使用了 https://github.com/nicklockwood/XMLDictionary )。
使用XMLParser字典将HTML文件的内容转换为NSDictionary。
converted content of HTML file into NSDictionary using XMLParser dictionary.
var maindic = NSDictionary(XMLFile:NSBundle.mainBundle()。 pathForResource(JSON-LD_Sample_Card,ofType:html))
var maindic = NSDictionary(XMLFile:NSBundle.mainBundle().pathForResource("JSON-LD_Sample_Card", ofType: "html"))
然后从字典中我们可以轻松获得数组不同的标签,我们也可以解析JSON-LD脚本标签。
Then from dictionary we can easily get array of different tags and there we can parse JSON-LD script Tag too.
这篇关于如何在Objective-C中从HTML中读取JSON-LD数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!