我正在开发一个物理应用程序,应该显示一个公式列表,甚至解决其中一些(唯一的问题是ListView)
这是我的主要布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:measureWithLargestChild="false"
android:orientation="vertical"
tools:context=".CatList" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/titlebar" >
<TextView
android:id="@+id/Title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ff1c00"
android:textIsSelectable="false" />
</RelativeLayout>
<ListView
android:id="@+id/listFormulas"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的主要活动
package com.wildsushii.quickphysics;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.view.Menu;
import android.widget.ListView;
public class CatList extends Activity {
public static String AssetJSONFile (String filename, Context context) throws IOException …Run Code Online (Sandbox Code Playgroud) 当我使用Gson(JsonParser.parse)解码以下内容时:
{ "item": "Bread", "cost": {"currency": "\u0024", "amount": "3"}, "description": "This is bread\u2122. \u00A92015" }
Run Code Online (Sandbox Code Playgroud)
“ currency”元素以字符串形式返回(并且不会转换为Unicode字符)。Gson中是否有可以帮助我的设置或方法?
如果不是,Android中是否可以将包含一个或多个转义字符序列(例如“ \ u0024”)的字符串转换为带有Unicode字符的输出字符串(无需编写自己的字符串,也无需使用Apache的StringEscapeUtils)?
我想避免添加另一个库(仅用于一个小功能)。
更新资料
看起来服务器在Unicode转义序列中两次转义了反斜杠。谢谢大家的帮助!