Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:41:32+00:00 2026-06-02T10:41:32+00:00

I am trying to consume PHP Web service with JSON in android I got

  • 0

I am trying to consume PHP Web service with JSON in android

I got response data from server as

string(170) "["14","Samsung","1","15","Nokia","1","16","Sony Ericson","1","18","LG","1","19","Iphone","1","21","HTC","1","22","Motorola","1","23","Micromax","1","41","BlackBerry","1"]"

How should i parse it to show it on a ListView.I am familiar about how to show data on ListView by creating custom adapter but I am unable to parse this output.Please help

I followed this tutorial to access PHP Web Service

http://www.codeproject.com/Articles/267023/Send-and-receive-json-between-android-and-php
Give me some reference.
Any help is appreciated.
Thank you…

Alos I would like to know what is the proper format of JSONArray generated at php side ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:41:33+00:00Added an answer on June 2, 2026 at 10:41 am

    It is valid but weird json response.
    When you parse this json you will get 27 values.
    14, samsung, 1, 15, nokia…
    But it seems every 3 item is an object like
    “14,samsung,1”
    “15,nokia,1”.
    And that json doesn’t reflect that.

    With an online json parser like this, you can see what result you can:

    http://jsonviewer.stack.hu/

    And you can parse that json like this:

    List<String> list = new ArrayList<String>();
    int counter = 0;
    boolean first = true;
    String json = "[\"14\",\"Samsung\",\"1\",\"15\",\"Nokia\",\"1\",\"16\",\"Sony Ericson\",\"1\",\"18\",\"LG\",\"1\",\"19\",\"Iphone\",\"1\",\"21\",\"HTC\",\"1\",\"22\",\"Motorola\",\"1\",\"23\",\"Micromax\",\"1\",\"41\",\"BlackBerry\",\"1\"]";
    JSONArray getJSONArray;
    try {
      getJSONArray = new JSONArray(json);
    
      for (int i = 0; i < getJSONArray.length(); i++) {
    
        Log.d("", getJSONArray.getString(i) + "-" + i % 1 + "-" + i % 2);
    
        if ((first == true && counter == 1) || (first == false && counter == 2)) {
          list.add(getJSONArray.getString(i));
          counter = 0;
          first = false;
        }
        else {
          counter += 1;
        }
      }
    }
    catch (JSONException e) {
      e.printStackTrace();
    }
    

    Log your array to see what you got:

    for (String item : list) {
      Log.d("list", item);
    }
    

    Results:

    D/list    ( 1669): Samsung
    D/list    ( 1669): Nokia
    D/list    ( 1669): Sony Ericson
    D/list    ( 1669): LG
    D/list    ( 1669): Iphone
    D/list    ( 1669): HTC
    D/list    ( 1669): Motorola
    D/list    ( 1669): Micromax
    D/list    ( 1669): BlackBerry
    

    And for the server site:

    Normally that json had to be like this..

    [
        {
            id: "14",
            brand: "Samsung",
            status: "1"
        },
        {
            id: "15",
            brand: "Nokia",
            status: "1"
        },
        {
            id: "16",
            brand: "Sony Ericson",
            status: "1"
        }
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to consume a web service on an Apache/PHP server for which
I'm trying to consume the following web service http://ipinfodb.com/ip_location_api.php this web service returns an
I'm trying to consume a hello world AXIS2 SOAP web service using a PHP
Im trying to consume a Java web-service, that uses a certificate. I could generate
I am trying to consume data from a webservice published by a 3rd party.
I'm trying to consume a SharePoint 2010 web service via Visual Studio 2010. I
I'm getting XSS errors when trying to consume a .NET web service and I'm
I'm trying to consume a remote Web service that uses HTTP basic authentication, using
I am trying to consume a .net web service, and get the following error
I'm trying to implement a stateful web service in PHP using the SOAP extension.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.