-3

I have a problem with the extraction of data from a JSON file that I receive from a PHP file

This is the filecontents of the JSON file I get:

{"success":1,"message":"Data of the Person", "0":{"Name":"Marco","Surname":"Rossi","Age":"32"}}

I tried to use the getString function but it gives me the error JSONException: No value for lane_prodoct

This is an excerpt of the function I use to recover my data:

success = jObj.getString("success");
UserNm = jObj.getString("Name");
UserSrm = jObj.getString("Surname");
UserAge= jObj.getString("Age");
Andrea
  • 128
  • 3
  • 13

1 Answers1

0

The JSON

{"success":1,"message":"Data of the Person", "0":{"Name":"Marco","Surname":"Rossi","Age":"32"}

here the last } is missing. It should be like

{"success":1,"message":"Data of the Person", "0":{"Name":"Marco","Surname":"Rossi","Age":"32"}}
Koustuv Ganguly
  • 897
  • 7
  • 21
  • The JSON I receive is formatted as you say !! in fact I corrected the post, What I do not understand is because the value of "success" I can extract it while others are not – Andrea May 14 '18 at 14:59
  • You need to construct `"0":{"Name":"Marco","Surname":"Rossi","Age":"32"}`as a json object.From that you need to query for `Name` – Koustuv Ganguly May 14 '18 at 15:01
  • Ok !! could you give me some indication before I tried creating another Json file and inserting the value "0" inside but it does not go: 'JSONObject jObj1 = jObj. [' 0 ']:' – Andrea May 14 '18 at 15:05
  • do like `JSONObject j1=jObj.getJSONObject("0");` now from j1 get the Name like `j1.getString("Name")` – Koustuv Ganguly May 14 '18 at 15:14
  • 1
    Thanks for your help – Andrea May 14 '18 at 15:15