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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:12:40+00:00 2026-05-31T22:12:40+00:00

I am new to JSON programming in J2ME. I discovered that Json is used

  • 0

I am new to JSON programming in J2ME.

I discovered that Json is used to exchange data much like XML.

I want to know about the exchange in Array object from JSONtoObject and vice versa

Below written is code where I convert from JSON to Object and vice versa.

But I don’t know about how to do for complex data structure like arrays etc.

// App Loader

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class AppLoader extends MIDlet {

    public AppLoader() {
        // TODO Auto-generated constructor stub

        // Converting Object to JSON

        UserData data=new UserData();
        data.setId(10);
        data.setName("Yatin");
        data.setDescription("Testing JSON in J2ME");
        System.out.println("Convert to JSON"+data.toJSON());


        //Convert JSON to Object
        String sample="{\"id\":99,\"name\":\"Tester\",\"description\":\"This is JSON Data\"}";
        UserData data2=new UserData();
        data2.fromJSON(sample);
        System.out.println("Convert from JSON "+data2);
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

    protected void pauseApp() {
        // TODO Auto-generated method stub

    }

    protected void startApp() throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

}

In this class I created getters and setters for the String type of objects and then created JsonObject to create a JSON object to create a JSON object and then vice versa as per functions toJSON() and fromJSON()

// User Data class

import org.json.me.JSONException;
import org.json.me.JSONObject;


public class UserData {
    private int id;
    private String name;
    private String description;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String toString()
    {
        return getId()+"-"+getName()+"-"+getDescription();
    }



    public String toJSON() {
        // TODO Auto-generated method stub
        JSONObject inner=new JSONObject();

        try {
            inner.put("id",getId());
            inner.put("description", getDescription());
            inner.put("name", getName());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return inner.toString();
    }

    public void fromJSON(String jsonString) {
        // TODO Auto-generated method stub
        try {
            JSONObject json=new JSONObject(jsonString);
            setId(json.getInt("id"));
            setDescription(json.getString("description"));
            setName(json.getString("name"));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



    }

}

i found a better link for this question

http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/

  • 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-05-31T22:12:41+00:00Added an answer on May 31, 2026 at 10:12 pm

    Check this link for different JSON Data Set Sample

    One Example for your Understanding::: JSON String Nested with Arrays

    {
        "id": "0001",
        "type": "donut",
        "name": "Cake",
        "ppu": 0.55,
        "batters":
            {
                "batter":
                    [
                        { "id": "1001", "type": "Regular" },
                        { "id": "1002", "type": "Chocolate" },
                        { "id": "1003", "type": "Blueberry" },
                        { "id": "1004", "type": "Devil's Food" }
                    ]
            },
        "topping":
            [
                { "id": "5001", "type": "None" },
                { "id": "5002", "type": "Glazed" },
                { "id": "5005", "type": "Sugar" },
                { "id": "5007", "type": "Powdered Sugar" },
                { "id": "5006", "type": "Chocolate with Sprinkles" },
                { "id": "5003", "type": "Chocolate" },
                { "id": "5004", "type": "Maple" }
            ]
    }
    

    To check its valid or not check this link (JSON Validator)

    To check JSON Viewer

    So Here is code take look::

    String json = "{\"id\":\"0001\",\"type\":\"donut\",\"name\":\"Cake\""
                    + ",\"ppu\":0.55,\"batters\":{\"batter\":["
                    + "{\"id\":\"1001\",\"type\":\"Regular\"},{\"id\":\"1002\","
                    + "\"type\":\"Chocolate\"},{\"id\":\"1003\","
                    + "\"type\": \"Blueberry\" },{ \"id\": \"1004\", "
                    + "\"type\": \"Devil's Food\" } ] },"
                    + " \"topping\":["
                    + "{ \"id\": \"5001\", \"type\": \"None\" },"
                    + "{ \"id\": \"5002\", \"type\": \"Glazed\" },"
                    + "{ \"id\": \"5005\", \"type\": \"Sugar\" },"
                    + "{ \"id\": \"5007\", \"type\": \"Powdered Sugar\" },"
                    + " { \"id\": \"5006\", \"type\": \"Chocolate with Sprinkles\" },"
                    + "{ \"id\": \"5003\", \"type\": \"Chocolate\" },"
                    + "{ \"id\": \"5004\", \"type\": \"Maple\" }]}";
            try {
                JSONObject root = new JSONObject(json);
                String id = root.getString("id");
                double dd = root.getDouble("ppu");
    
                System.out.println(""+id);
                System.out.println(""+dd);
    
                JSONObject batters=new JSONObject(root.getString("batters"));
                JSONArray batter=new JSONArray(batters.getString("batter"));
    
                for(int j=0;j<batter.length();j++){
                    JSONObject navgt_batter=new JSONObject(batter.getString(j));
                     String id_batter= navgt_batter.getString("id");
                    String type_batter=navgt_batter.getString("type");
                      System.out.println(""+id+" "+type_batter);
                }
    
                JSONArray topping=root.getJSONArray("topping");
                 for(int k=0;k<topping.length();k++){
                     JSONObject navgt_batter=new JSONObject(topping.getString(k));
                     String id_top =navgt_batter.getString("id");
                    String type_top=navgt_batter.getString("type");
                     System.out.println(""+id_top+" "+type_top);
                 }
    
            } catch (JSONException ex) {
                ex.printStackTrace();
            }
    

    You can use your same concept to set & get data like above you did. complex data structure always easy to handle in JSON, don’t worry about it. Thanks

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

Sidebar

Related Questions

I'm new in Android programming and I want to find how to store data
I'm new to PHP programming and have poor knowledge about it, but I want
I have a problem accessing JSON data. I'm new to JSON and jquery so
This is my JSON data: { ACT: Australian Capital Territory, NSW: New South Wales,
I'm quite new to iphone programming and I want to do the following stuff:
I want to dynamically append data received via an url in JSOn format to
I am programming an API that would be used by both a web app
I'm relatively new to Java programming and need to parse a complex JSON object
I am new to programming especially jQuery and webservices. I want to pass the
How would I go about getting the new posts of a subreddit in JSON?

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.