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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:11:42+00:00 2026-06-12T15:11:42+00:00

Ran into a situation where am not sure how to handle it. I have

  • 0

Ran into a situation where am not sure how to handle it.

I have json data that comes from a server; for example:(am just posting part of the json, so, yes, the json is valid)

    "wall_id": 889149,
    "poster_image_thumbnail": "http:\/\/www.mface.me\/images\/avatar\/thumb_62441559ddb1dda7513d0f94.jpg",
    "post_type": "profile",
    "post_content": [{
        "text": "",
        "images_count": 1,
        "images": ["https:\/\/fbcdn-sphotos-a-a.akamaihd.net\/hphotos-ak-ash4\/227408_475848819113499_663318592_n.jpg"]
    }]

Created a class to store this json data

public class feedFormat{
    Integer wall_id;
    String poster_image_thumbnail;
    String post_type;
    String post_content;
}

There are times when post_content can be empty or an array as the example above. I have declared post_content as String in feedFormat. This is obviously throwing a cast exception (Converting array to string?).

I was expecting JSONObject to read it as a string and later convert it into an array from there, but does’nt seem to go that way.

How can i dynamically handle a string or an array? if it is an array, i need to break it down.

I am porting this app from IOS to android, there is a “id” object in IOS that can be of any class. I check if the class is a NSSTring or NSArray and take it from there. Here in Java, am not sure how to handle it.

Any suggestions are highly appreciated

  • 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-12T15:11:44+00:00Added an answer on June 12, 2026 at 3:11 pm

    If your JSON array is empty, it will be like that :

    "post_content": []
    

    It will then remain an array, with the particularity of being 0-sized.

    Then I suggest you parse directly your JSON array into a appropriate data structure, whatever the size, like an ArrayList> for example. You will then be able to go through all the items of your JSON array, and for each item, add a new HashMap in your arraylist. Every hashmap will contain there pairs of key values.

    However, if I understand well your JSON, it seems that it will be always an array of three elements, the third element being itself a array, which size is given bu the attribute images_count. This is not very good, your JSON structure should be :

    "post_content": {
        "text": "",
        "images": [
            "https://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-ash4/227408_475848819113499_663318592_n.jpg"
        ]
    }
    

    Since images is an array, you can easily get its size.

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

Sidebar

Related Questions

I ran into this situation today. I have an object which I'm testing for
I ran into a situation today where Java was not invoking the method I
I just ran into a situation related to this SO question: How to tell
I have ran into a situation at work where it has been proposed to
I recently ran into a situation in which accessing session information from view is
I ran into a situation where I need access to a javascript object from
I have ran into 2 situations already that feel like they could be solved
I ran into a situation that seems to suggest otherwise. In the following code
I just ran into a situation where I needed to patch a release with
I'm working on some legacy code and I ran into something that I'm not

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.