This question has already been answered:

Hello. Need to parse such a json, how to do it?

{"code":200,"lang":"en-ru","text":["привет"]} 

PS The problem is that I can not pull the value of "text".

What I wrote:

  try { JSONObject jObject = new JSONObject(strJson); JSONArray jArray = jObject.getJSONArray("text"); JSONObject two = jArray.getJSONObject(0); Toast.makeText(service.this, two.toString(), Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); } 

What's on output: ["привет"]

How to pull out this 0th array?

Marked as a duplicate by participants Vladimir Martyanov , iksuy , HamSter , Viktor Tomilov , 0xdb Mar 2 '18 at 23:38 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Do you seriously think that you are the first person who parses JSON in Java? - Vladimir Martyanov
  • jArray.getString(0); try it. - eugeneek 2:55 pm
  • Thank you, that's right, you literally just finished it and you wrote: D - CrazyProgrammist

1 answer 1

The issue is resolved. (Thanks eugeneek)

 try { JSONObject jObject = new JSONObject(strJson); JSONArray jArray = jObject.getJSONArray("text"); String getget = jArray.getString(0); Toast.makeText(service.this, getget, Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); }