0

場所を取得するための API があります。

Web ブラウザを使用すると、次のように表示されます。

<placeID>5</placeID>
<placeName>!@#$%&*?/_"'()-+;</placeName>
<rating>0</rating>
<categoryID>2</categoryID>
</place>

HttpGet を使用してコンソールに出力すると、次のように表示されます。

<place>
<placeID>5</placeID>
<placeName>!@#$%&amp;*?/_&quot;'()-+;</placeName>
<rating>0</rating>
<categoryID>2</categoryID>
</place>

AndroidでplaceNameを表示すると、!@#$%

生の文字列をデータベースに保存し、API で htmlspecialchars($placeName) を使用します。

問題は と同じで?~=\^[]{}&lt;&gt;:);):(:'(:o:P:$:S?~=\^[]{}&lt;&gt;:);):(:'(:o:P:$:Sコンソールと?~=\^[]{}Android で発生します。

データベースに保存されているのと同じように、Android ですべての特殊文字を表示したいと考えています。

4

1 に答える 1

1

The web browser is showing you the first result (unescaped) because it's converting the &amp; to & for display. If you do "View Source" in your browser you will see that it's actually &amp; just like with HttpGet. That is exactly what you want happening; what you see in the console is correct.

That said, you shouldn't be having any problems just outputting that string in Android, since it's clearly escaped properly. So, the problem is most likely in your parser, like in this thread: Android SAX parser not getting full text from between tags

Even if you're not using SAXParser, your parsing code is where you should look for a problem at this point, not at the data coming in.

Just to be safe, try also using the ENT_QUOTES flag with htmlspecialchars in your API, although that doesn't seem to be the problem in this specific case.

I should also mention that once you get that problem solved, depending on how you're displaying the text on Android it may show up escaped like in console, where you see things like &amp; instead of &. If that's the case, you will need to then decode the string from the XML like in this thread: Java: How to unescape HTML character entities in Java?

于 2012-07-28T10:32:31.957 に答える