android json html标签,Android: Parsing HTML tags in JSON

问题

can anybody help me parsing HTML tags in JSON?

I got tags like ,

, etc. on the values of my JSON file. And I want to be able to parse them, so the text which is displayed on my app is shown based on the HTML tags.

here's my JSON parsing code:

void examineJSONFile()

{

try

{

String y = "";

InputStream is = this.getResources().openRawResource(R.raw.uni);

Writer writer = new StringWriter();

char[] buffer = new char[1024];

try {

BufferedReader reader = new BufferedReader(

new InputStreamReader(is, "Unicode")

);

int n;

while ((n = reader.read(buffer)) != -1) {

writer.write(buffer, 0, n);

}

} finally {

is.close();

}

String jsontext = writer.toString();

JSONArray entries = new JSONArray(jsontext);

int j;

for (j=0;j

{

JSONObject post = entries.getJSONObject(j);

y += post.getString("description") + "\n";

}

txt_beschreibung.setText(y);

}

catch (Exception je)

{

txt_beschreibung.setText("Error w/file: " + je.getMessage());

}

}

and here's the sample of my JSON file:

[{

"title": "CARE Deutschland-Luxemburg e.V.",

"keyword": "CARE",

"description": "

Das CARE-Komplett-Paket für Menschen in Not

Schnell, nachhaltig und durchdacht, das ist das moderne CARE-Paket. CARE ist überzeugt, dass umfassende Hilfe von drei Seiten notwendig ist, um die weltweite Armut Schritt für Schritt zu verringern. Deswegen hat CARE sich seit seiner Gründung 1945 und dem Abwurf der ersten CARE-Pakete über Berlin weiter entwickelt. Heute steckt im CARE-Paket weit mehr als Zucker und Mehl. Heute bietet die Organisation in 70 der ärmsten Länder der Welt ein Komplett-Paket für Menschen in Not.

Das Komplett-Paket für Menschen in Not enthält:

*sofortige Nothilfe nach Katastrophen
*langfristige Entwicklungszusammenarbeit
*Schutz der Menschenrechte
",

"smallImageUrl": "http://cdn.spendino.de/web/img/projects/home/1284113658.jpg",

"bigImageUrl":"http://cdn.spendino.de/web/img/projects/small/1284113658.jpg",

"cost": "5"

},

{

"title": "Brot für die Welt",

"keyword": "BROT",

"description": "

„Brot für die Welt“ unterstützt unter der Maßgabe 'Helfen, wo die Not am größten ist' ausgewählte Projekte weltweit.

Von Angola bis Tansania, von der Förderung von Mahlzeiten bis zur gesundheitlichen Grundversorgung und Katastrophenhilfe.

Bei ihrem täglichen Kampf gegen Krankheiten, Hunger, Ungerechtigkeiten und Armut wird die Aktion „Brot für die Welt“ von der evangelischen Kirche unterstützt.

Die Aktion hat es sich zum Ziel gesetzt, die Entwicklungszusammenarbeit auf der ganzen Welt zu fördern und Hilfe zur Selbsthilfe zu leisten.

",

"smallImageUrl": "http://cdn.spendino.de/web/img/projects/home/1267454286.jpg",

"bigImageUrl":"http://cdn.spendino.de/web/img/projects/small/1267454286.jpg",

"cost": "5"

}]

Anything I can add on my method. I'm looking for a specific answer to my problem but I open to any kind of solution.

Thank you

回答1:

Have a look at android.text.Html.

You can use this to do something like:

textView.setText(Html.fromHtml("Hello, I am bold"));

回答2:

android.text.Html could be your friend here.

static Spanned Html.fromHtml(

String source,

Html.ImageGetter imageGetter,

Html.TagHandler tagHandler )

http://developer.android.com/reference/android/text/Html.html

来源:https://stackoverflow.com/questions/5539168/android-parsing-html-tags-in-json

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值