0

I have a problem with JSON I get a json since https://proxyepn-test.epnbn.net/wsapi/epn

But when I want to display a single data eg "name". The console displays:

Log

org.json.JSONException: No value for Name
org.json.JSONException: Value status at 0 of the type java.lang.String can not be converted to JSONObject

Can you help me ? Thanks.

here is my code :

String test2 = test.execute(restURL).get().toString();
        Log.i("result",test2);
JSONObject obj = new JSONObject(test2);
        String data = obj.getString("data");
        Log.i("testjson",data);
        String pageName = obj.getJSONObject("data").getString("Name");
        Log.i("testjsondata",pageName);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
SripadRaj
  • 1,687
  • 2
  • 22
  • 33

3 Answers3

0
JSONObject obj = new JSONObject(test2);
JSONObject data=obj.getJSONobject("data");
JSONObject ob1=obj.getJSONobject("1");
String pageName = ob1.getString("Name");
D.J
  • 1,439
  • 1
  • 12
  • 23
0

Try below:

JSONObject obj = new JSONObject(test2);
JSONObject data = obj.getJSONObject("data");
Iterator<String> iterator = data.keys();
while(iterator.hasNext()){
        String key = iterator.next();
        String Name = data.getString(key);
}
Shridutt Kothari
  • 7,326
  • 3
  • 41
  • 61
0

You have to parse your next level of JSONObject (labeled as "1","2","3".. from response).

It seems like issue in Json response structure you shared. why cann't it be array inside "data"?

Then you can easily read data as JSONArray with those objects as ("1","2","3"..) array item.

Else

Android JSON parsing of multiple JSONObjects inside JSONObject

Community
  • 1
  • 1