iphone - 从 mediawiki xml 格式 api 获取出生日期、出生地

标签 iphone ios objective-c wikipedia-api mediawiki-api

我正在尝试从 objective-c 中的 MediaWiki 获取某人的详细信息。我正在使用http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvsection=0&titles=Albert_Einstein&format=xml

我收到的响应数据如下:

</i>$0 = 0x07562e60 <?xml version="1.0"?><api><query><normalized><n     from="Albert_Einstein" to="Albert Einstein" /></normalized><pages><page pageid="736" ns="0" title="Albert Einstein"><revisions><rev contentformat="text/x-wiki" contentmodel="wikitext"     xml:space="preserve">{{Redirect|Einstein}}
{{Good article}}
{{pp-semi|small=yes}}{{pp-move-indef}}
{{Infobox scientist
| name        = Albert Einstein
| image       = Einstein 1921 by F Schmutzer.jpg
| caption     = Albert Einstein in 1921
| birth_date  = {{Birth date|df=yes|1879|3|14}}
| birth_place = [[Ulm]], [[Kingdom of Württemberg]], [[German Empire]]
| death_date  = {{Death date and age|df=yes|1955|4|18|1879|3|14}}
| death_place = {{nowrap|[[Princeton, New Jersey|Princeton]], [[New Jersey]], U.S.}}
| children    = [[Lieserl Einstein|Lieserl]] (1902-1903?)&lt;br /&gt;[[Hans Albert     Einstein|Hans Albert]] (1904-1973)&lt;br /&gt;[[Eduard Einstein|Eduard &quot;Tete&quot;]] (1910-1965)
| spouse      = [[Mileva Marić]]&amp;nbsp;(1903–1919)&lt;br /&gt;{{nowrap|[[Elsa  Löwenthal]]&amp;nbsp;(1919–1936)}}
| residence   = Germany, Italy, Switzerland, Austria, Belgium, United States
| citizenship = {{Plainlist|
</i>

现在我想获取 Objective-c 中人的生日。不知怎的,我也能设法得到birth_date。但我的问题是,是否有任何适当的解析可用于解析这些数据?

最佳答案

这不是办法。将 Web API 与某些 client library 一起使用。更好的是,使用正确的 API,即 – 对于数据问题 – 维基数据。

参见wbgetclaims docs示例:https://www.wikidata.org/w/api.php?action=wbgetclaims&entity=Q937&property=P569给出

{
    "claims": {
        "P569": [
            {
                "id": "q937$2ecb21c3-4db1-54e8-27c4-a8a40541930c",
                "mainsnak": {
                    "snaktype": "value",
                    "property": "P569",
                    "datatype": "time",
                    "datavalue": {
                        "value": {
                            "time": "+00000001879-03-14T00:00:00Z",
                            "timezone": 0,
                            "before": 0,
                            "after": 0,
                            "precision": 11,
                            "calendarmodel": "http://www.wikidata.org/entity/Q1985727"
                        },
                        "type": "time"
                    }
                },
                "type": "statement",
                "rank": "normal",
                "references": [
                    {
                        "hash": "d6e3ab4045fb3f3feea77895bc6b27e663fc878a",
                        "snaks": {
                            "P143": [
                                {
                                    "snaktype": "value",
                                    "property": "P143",
                                    "datatype": "wikibase-item",
                                    "datavalue": {
                                        "value": {
                                            "entity-type": "item",
                                            "numeric-id": 206855
                                        },
                                        "type": "wikibase-entityid"
                                    }
                                }
                            ]
                        },
                        "snaks-order": [
                            "P143"
                        ]
                    },
                    {
                        "hash": "7eb64cf9621d34c54fd4bd040ed4b61a88c4a1a0",
                        "snaks": {
                            "P143": [
                                {
                                    "snaktype": "value",
                                    "property": "P143",
                                    "datatype": "wikibase-item",
                                    "datavalue": {
                                        "value": {
                                            "entity-type": "item",
                                            "numeric-id": 328
                                        },
                                        "type": "wikibase-entityid"
                                    }
                                }
                            ]
                        },
                        "snaks-order": [
                            "P143"
                        ]
                    },
                    {
                        "hash": "f991bf419530b161a136a5c4e55c49909074ce49",
                        "snaks": {
                            "P248": [
                                {
                                    "snaktype": "value",
                                    "property": "P248",
                                    "datatype": "wikibase-item",
                                    "datavalue": {
                                        "value": {
                                            "entity-type": "item",
                                            "numeric-id": 36578
                                        },
                                        "type": "wikibase-entityid"
                                    }
                                }
                            ],
                            "P813": [
                                {
                                    "snaktype": "value",
                                    "property": "P813",
                                    "datatype": "time",
                                    "datavalue": {
                                        "value": {
                                            "time": "+00000002014-04-09T00:00:00Z",
                                            "timezone": 0,
                                            "before": 0,
                                            "after": 0,
                                            "precision": 11,
                                            "calendarmodel": "http://www.wikidata.org/entity/Q1985727"
                                        },
                                        "type": "time"
                                    }
                                }
                            ]
                        },
                        "snaks-order": [
                            "P248",
                            "P813"
                        ]
                    }
                ]
            }
        ]
    }
}

关于iphone - 从 mediawiki xml 格式 api 获取出生日期、出生地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17854633/

相关文章:

java - Linux 服务器上的 HTTP 直播

ios - 使用 Alamofire 和 multipart/form-data

ios - UINavigationItem 未显示在我的 ViewController 中

ios - 通过 segue 将数组发送到新的 View Controller swift iOS 9

ios - UILabel 下边框和右边框

objective-c - 观察RACSequence中的每一项

iphone - 在ios中用字符串追加字符串

iphone - 在 iPhone 模拟器中从硬盘读取文件

ios - 递归 block 过早释放

objective-c - 接收udp广播包ios