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 8087589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:49:31+00:00 2026-06-05T18:49:31+00:00

My first post here :) I have a summer job doing a bit of

  • 0

My first post here 🙂

I have a summer job doing a bit of coding – I’m definitely not a pro, yet!

I’m converting this iPhone app to Android, it’s nearly done. Just struggling converting this piece.

The array of ‘participants’ gets passed to a server via JSON.
This to me, in Android, looks like it would be an array of HashMaps. Is that correct?

Here is the Objective C:

NSMutableArray *participants = [[NSMutableArray alloc] init];

NSArray *listOfParticipants = [[game getListOfGameParticipants]allValues];

for (Player *playerObj in listOfParticipants)
{
    NSMutableDictionary *playerToAdd = [[NSMutableDictionary alloc] init];
    if ([playerObj.email length] == 0) {
        [playerToAdd setValue:playerObj.phoneNumber forKey:@"Id"];
    }
    else
    {
        [playerToAdd setValue:playerObj.email forKey:@"Id"];
    }

    [playerToAdd setValue:playerObj.firstName forKey:@"FirstName"];
    [playerToAdd setValue:playerObj.lastName forKey:@"LastName"];
    [playerToAdd setValue:playerObj.phoneNumber forKey:@"PhoneNumber"];

    [participants addObject:playerToAdd];

    [playerToAdd release];
}

The getListOfGameParticipants is:

- (NSDictionary*) getListOfGameParticipants
{
return participants ;
}

and the Android code I’ve attempted is:

ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> playersObject = new HashMap<String, String>();
            playersObject.put("Id", "test@test.net");
            playersObject.put("FirstName", "Test Firstname");
            playersObject.put("LastName", "Test Surname");
            playersObject.put("PhoneNumber", "Test Number");
            list.add(playersObject);
json.put("ParticipantIds", list);

Please help 🙂

Edit: It doesn’t work. The server reports back:

The server encountered an error processing the request. The exception message is 'Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''. '. See server logs for more details.

The data type expected is:

[DataMember]
public Player[] ParticipantIds { get; set; }

Edit: Further update:

I now have my array of hashmaps parsing to a JSON string in a good format. I need to parse that JSON string to a JSONObject and put that JSONObject in a JSONArray.

The following code doesn’t work:

Map<String, String> playersObject = new HashMap<String, String>();
            playersObject.put("PhoneNumber", "TestNumber");
            playersObject.put("Id", "test@test.net");
            playersObject.put("FirstName", "Test Firstname");
            playersObject.put("LastName", "Test Surname");
            ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
            list.add(playersObject);
            String jsonValue = org.json.simple.JSONValue.toJSONString(list);
            JSONObject hashMapObject = new JSONObject();
            hashMapObject.getString(jsonValue);
            JSONArray hashMapArray = new JSONArray(jsonValue);
            hashMapArray.put(hashMapObject);

It gives the error:

org.json.JSONException: No value for [{"LastName":"Test Surname","FirstName":"Test Firstname","Id":"test@test.net","PhoneNumber":"TestNumber"}]

Help!

  • 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-05T18:49:33+00:00Added an answer on June 5, 2026 at 6:49 pm

    The Android code does not do the same thing as the iPhone code, but as far as the data structure goes it seems correct. Just compare the JSON generated by the two methods and you’ll know what’s wrong.

    This is the JSON code the iPhone is generating:

    [
        {
            "Id" : "value",
            "FirstName" : "value",
            "LastName" : "value",
            "PhoneNumber" : "value"
        },
        {
            "Id" : "value",
            "FirstName" : "value",
            "LastName" : "value",
            "PhoneNumber" : "value"
        },
        {
            "Id" : "value",
            "FirstName" : "value",
            "LastName" : "value",
            "PhoneNumber" : "value"
        }
    ]
    

    Just make sure the Android code is generating the same thing.

    EDIT:

    The code for manually generating JSON in Java would look something like:

    String json = "[";
    
    for (Player player : participants) {
        json += "{";
        json += "\"Id\":\"" + (player.email.length() > 0 ? player.email : player.phoneNumber) + "\",";
        json += "\"FirstName\":\"" + player.firstName + "\",";
        json += "\"LastName\":\"" + player.lastName + "\",";
        json += "\"PhoneNumber\":\"" + player.phoneNumber + "\"";
        json += "},";
    }
    
    json = json.substring(0, json.length()-1) + "]";
    

    I don’t write Java code very often, but I think the above generates the same JSON as the Objective-C code you posted. It’s not indented, but I don’t think the server will care.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here. I have a problem. I need to take
Hello all this is my first post here i have been working in an
This is my first post here. I have been reading posts here since I
Well, this is my first post here and really enjoying the site. I have
This is my first post here in StackOverflow. I am not a newbie to
This is my first post here so kindly pardon any mistakes that I have.
This is my first post here, recently i have been working with JSF2.0 with
My first post here, so i hope this is the right area. I am
this is my first post here on stackoverflow and am very impressed by the
I'm new to Java and this is my first post on here so hopefully

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.