尝试从 Wiki API 解析数学表达式 JSON
Trying to parse Math Expressions JSON from Wiki API
我在我的应用程序中解析来自 Wiki api 的 JSON 使用 volley 请求没有问题,除了以下请求。我需要将这些表达式与文本一起解析。
我正在使用这个 URL(例如):
这是文章中有问题的部分:
解析工作得很好,但是当涉及到数学表达式时,它在 API:
中看起来像这样
在我的应用程序中,我与“{displaystyle =”部分的文本相处融洽。
我没有得到“/n”之类的东西。
在我的应用程序中,它看起来像这样:
我得到了很多空间和这个“{displaystyle”。文字吓坏了。我可以做些什么来克服这个问题吗?我找不到 api 查询,但也许我可以用 JSON 响应本身做点什么。
谢谢。
formatversion=2
API:Data formats#JSON parameters
Specify formatversion=2
for to get json (and php) format responses in a cleaner format. This also encodes most non-ASCII characters as UTF-8. MW 1.25+
所以:https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=Partition%20function%20(statistical%20mechanics)&formatversion=2 returns JSON 包含 <math>
标记,例如:
<annotation encoding=\"application/x-tex\">{\displaystyle \beta }</annotation>
这可能更有用。
有关 formatversion=2
的更多信息,请访问 API:JSON version 2
format=json
suffers from a number of shortcomings that make it more difficult to use than necessary. Many of these arise because XML was the original output format and the underlying data structure of API responses was designed around this.
To address this, after discussion MediaWiki 1.25
introduces a new JSON response format. It is not the default, you only get results in the new format if you specify formatversion=2
, and it's only for the json
and php
formats (and their human-readable jsonfm
and phpfm
variants).
我在我的应用程序中解析来自 Wiki api 的 JSON 使用 volley 请求没有问题,除了以下请求。我需要将这些表达式与文本一起解析。
我正在使用这个 URL(例如):
这是文章中有问题的部分:
解析工作得很好,但是当涉及到数学表达式时,它在 API:
中看起来像这样在我的应用程序中,我与“{displaystyle =”部分的文本相处融洽。 我没有得到“/n”之类的东西。 在我的应用程序中,它看起来像这样:
我得到了很多空间和这个“{displaystyle”。文字吓坏了。我可以做些什么来克服这个问题吗?我找不到 api 查询,但也许我可以用 JSON 响应本身做点什么。
谢谢。
formatversion=2
API:Data formats#JSON parameters
Specify
formatversion=2
for to get json (and php) format responses in a cleaner format. This also encodes most non-ASCII characters as UTF-8.MW 1.25+
所以:https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=Partition%20function%20(statistical%20mechanics)&formatversion=2 returns JSON 包含 <math>
标记,例如:
<annotation encoding=\"application/x-tex\">{\displaystyle \beta }</annotation>
这可能更有用。
有关 formatversion=2
的更多信息,请访问 API:JSON version 2
format=json
suffers from a number of shortcomings that make it more difficult to use than necessary. Many of these arise because XML was the original output format and the underlying data structure of API responses was designed around this.To address this, after discussion MediaWiki
1.25
introduces a new JSON response format. It is not the default, you only get results in the new format if you specifyformatversion=2
, and it's only for thejson
andphp
formats (and their human-readablejsonfm
andphpfm
variants).