0

I've json like this

array (
  'status' => 'OK',
  'categories' => 
  array (
    'Sepeda' => 
    array (
      83 => 'Sepeda MTB',
      'Fullbike' => 
      array (
        370 => 'MTB',
        371 => 'Roadbike',
        374 => 'Fixie',
        375 => 'Sepeda Lipat',
        378 => 'City Bike',
        380 => 'BMX',
        382 => 'Onthel',
      ),

that I wanna ask , how code to get "Fullbike" ?? thanks for your advice , really need help , thanks

user1920582
  • 245
  • 1
  • 6
  • 17

2 Answers2

0

Checkout the PHP docs to get your array to JSON: PHP:json_encode

Alternatively, could parse the PHP array as it is, but that doesn't sound like fun.

Second checkout the Android JSON handling docs to see how to process JSON with Android. That's best done with JSONObject

Here's an example

String getJsonThingy(String rawJson) {
String strFullBike = "";
        try {
            JSONObject json = new JSONObject(rawJson);
            JSONObject jsonCategories = json.getJSONObject("categories");
            JSONObject jsonSepeda = jsonCategories.getJSONObject("Sepeda");
            strFullBike = jsonSepeda.getString("Fullbike");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return strFullBike;

I'd like to point out that this code isn't what you want your final product to look like -- it's a start.

Also, check out these related SO questions to help you get a better idea of what you should be looking for.

Final note: It may not be a bad idea for your Android client to ask your server for specific parts of your array, as seeing how your array is nested.

Community
  • 1
  • 1
isaacparrot
  • 1,918
  • 17
  • 24
0
try {
     //get Full Bike Json object first
     JSONObject jsonObject = response.getJSONObject("categories").getJSONObject("Sepeda").getJSONObject("Fullbike");
     //Get inner values like this now
      String mtb = jsonObject.getString("370");
      Log.e("Response", mtb);           
} catch (JSONException e) {
      e.printStackTrace(); 
}
Varundroid
  • 9,135
  • 14
  • 63
  • 93