我想使用齐射来解析JSON响应,JSON响应中也包含印地语数据,所以如何在测试视图中获取该印地语数据
我刚刚使用JSONObject
和JSONArray
解析JSON数组,并使用getString()
方法获取数据。
final String URL = "http://poojavidhi.webepower.biz/getSubCategory";
StringRequest request = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
dialog.cancel();
Log.d("1234","responce array "+response.toString());
JSONObject jsonObject = new JSONObject(response);
JSONArray array = jsonObject.getJSONArray("sub_cat_list");
Log.d("1324","responce array "+array.toString());
for (int i = 0; i < array.length(); i++) {
JSONObject main_recipes = array.getJSONObject(i);
SubCatPojo pojo = new SubCatPojo();
pojo.setCatId(main_recipes.getString("id"));
pojo.setCatName(main_recipes.getString("name"));
pojo.setCatImage(main_recipes.getString("image"));
arrayList.add(pojo);
}
adapter.notifyDataSetChanged();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
dialog.cancel();
Toast.makeText(Listing.this, "error in network", Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> map = new HashMap<>();
map.put("p_id", catId);
return map;
}
};
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(request);
但是在logcat中,我得到了这个回复
{ "sub_cat_list":[{"id":6,"name":"\u0936\u094d\u0930\u0940 \u0917\u0923\u0947\u0936 \u0906\u0930\u0924\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/\/banner_img\/shree-ganesh-ji.png"},{"id":7,"name":"\u0913\u092e \u091c\u092f \u091c\u0917\u0926\u0940\u0936 \u0939\u0930\u0947 \u0906\u0930\u0924\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/\/banner_img\/vishnu-ji.png"},{"id":8,"name":"\u0926\u0941\u0930\u094d\u0917\u093e \u0906\u0930\u0924\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/\/banner_img\/durga_ma.png"},{"id":9,"name":"\u0906\u0930\u0924\u0940 \u0936\u094d\u0930\u0940 \u0932\u0915\u094d\u0937\u094d\u092e\u0940 \u092e\u093e\u0924\u093e ","img_url":"http:\/\/poojavidhi.webepower.biz\/\/banner_img\/laxmi_ma.png"},{"id":10,"name":"\u0936\u093f\u0935 \u0906\u0930\u0924\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/\/banner_img\/shiv.png"},{"id":11,"name":"\u0936\u094d\u0930\u0940 \u0939\u0928\u0941\u092e\u093e\u0928 \u0906\u0930\u0924\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/\/banner_img\/hanuman_ji.png"},{"id":12,"name":"\u0936\u094d\u0930\u0940 \u0938\u0930\u0938\u094d\u0935\u0924\u0940 \u0906\u0930\u0924\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/banner_img\/sarswati_maa.png"},{"id":13,"name":"\u0915\u0941\u0902\u091c \u092c\u093f\u0939\u093e\u0930\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/\/banner_img\/Kunj_Bihari.png"},{"id":14,"name":"\u0936\u094d\u0930\u0940 \u0936\u0928\u093f \u0926\u0947\u0935 \u0915\u0940 \u0906\u0930\u0924\u0940","img_url":"http:\/\/poojavidhi.webepower.biz\/banner_img\/shani_dev.png"}]}
答案 0 :(得分:0)
import android.text.Html;
String base = "\u0936\u094d\u0930\u0940 \u0917\u0923\u0947\u0936 \u0906\u0930\u0924\u0940";
String decoded = Html.fromHtml(base,Html.FROM_HTML_MODE_COMPACT).toString();
已解码:श्रीगणेशररी
现在,我并没有真正深入研究flags you can use,但是这个似乎很有效。如果您偶然发现问题,则绝对应该尝试其他标志。
答案 1 :(得分:0)
使用核心Java,只需要将Unicode字符转换为UTF-8。
首先,在遍历对象时获取键“名称”的值,然后尝试应用下面的代码,然后再次设置与键“名称”相对应的值。
我只是展示了转换方式,它是示例字符串的一部分。
String string ="\u0913\u092e \u091c\u092f \u091c\u0917\u0926\u0940\u0936 \u0939\u0930\u0947 \u0906\u0930\u0924\u0940";
byte[] utf8 = string.getBytes("UTF-8");
string = new String(utf8, "UTF-8");
System.out.println(string);
它将为您提供以下输出:'ओमओमजगदीशेेेेआआ