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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:56:37+00:00 2026-06-09T03:56:37+00:00

This is my Json: {array:[ {pid:1,product:test,size:[ {id:26,size:6-13 weeks}, {id:25,size:1-5 weeks}]}, {pid:2,product:test2,size:[ {id:31,size:86\/92}, {id:27,size:74\/80}]}]} I

  • 0

This is my Json:

{"array":[
          {"pid":"1","product":"test","size":[
                                              {"id":"26","size":"6-13 weeks"},
                                              {"id":"25","size":"1-5 weeks"}]},
          {"pid":"2","product":"test2","size":[
                                              {"id":"31","size":"86\/92"},
                                              {"id":"27","size":"74\/80"}]}]}

I generated the files with jsongen.byingtondesign.com but I can’t seem to figure out how to get the data (I looked at lots of Tutorials but I just get more confused because they are all different.)

I need to get the data depending on pid and id. I need to output the product string with pid … or the size string with id …. (Should I restructure my json?)

Just need a few tips to get me further.

Thanks!

  • 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-09T03:56:38+00:00Added an answer on June 9, 2026 at 3:56 am

    The structure you need is something like

    class Size {int id; String size;}
    class Product {int pid; String product; List<Size> size;}
    class Shop {List<Product> products;}
    

    and then just call

    Shop shop = gson.fromJson(jsonString, Shop.class);
    

    Here, I could never remember what is what. The structure looks fine, the names do not. I’d suggest something like

    class Size {int id; String name;}
    class Product {int id; String name; List<Size> sizes;}
    class Shop {List<Product> products;}
    

    Now I see you’d prefer a sort of map. This is something you can do easily in Java, but you can put it into Json as well. However, you either introduce redundancy or lose the id from the objects. Instead of

    [
        {"id":"26","size":"6-13 weeks"},
        {"id":"25","size":"1-5 weeks"}
    ]
    

    you can use either

    {
        "26": {"id":"26","size":"6-13 weeks"},
        "25": {"id":"25","size":"1-5 weeks"}
    }
    

    (with redundancy) or

    {
        "26": {"size":"6-13 weeks"},
        "25": {"size":"1-5 weeks"}
    }
    

    (with the Size object missing its id) or

    {
        "26": "6-13 weeks",
        "25": "1-5 weeks"
    }
    

    which is compact, but hardly extensible. In any case, I’d start with Java instead of Json, this makes things easier, as it’s Java you’re gonna deal with a lot. The Json string gets written and read by Gson, so you don’t need to care much how it looks like.

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

Sidebar

Related Questions

I'm trying to parse this JSON Array: http://www.ifanatic.hu/api/get_recent_posts/?dev=1 But I get this error: 2012-07-15
I have a JSON array like this [{Email:someone@some.com,Name:ACO,Groups:[MOD_SW,MOD_PI,MOD_GE],Id:63,Url:aco}, {Email:someone@some.com,Name:Agpo,Groups:[MOD_PI],Id:22,Url:agpo}, {Email:someone@some.com,Name:Akatherm,Groups:[MOD_SW],Id:64,Url:akatherm}, {Email:someone@some.com,Name:Albrand,Groups:[MOD_PI,MOD_GE],Id:23,Url:albrand}] I want to
i have this json array response: [ { status: active, url: https:\/\/ikiosk.podio.com\/dev\/apps\/myusers, url_label: myusers,
How can i convert this JSON array: This is a serialized JSON array 2012-06-18
I am trying to deserialize this JSON array into my android project. [{Name:Ban,Price:1},{Name:Banana,Price:1},{Name:chicken,Price:14},{Name:pizza,Price:16},{Name:slice,Price:1}] I
i have this JSON: var projects_array = new Array( {name:myName1, id:myid1, index:1}, {name:myName2, id:myid2,
I've json array like this: {GetReportResult: [ {bulan:4,total:2448,type:CHEESE1K,uang:8847823}, {bulan:4,total:572476,type:ESL,uang:5863408410}, {bulan:4,total:46008,type:ESL500ML,uang:234498301}, {bulan:5,total:5703,type:CHEESE1K,uang:134929306}, {bulan:5,total:648663,type:ESL,uang:6645764498}, {bulan:5,total:51958,type:WHP,uang:631994613}, {bulan:6,total:6190,type:CHEESE1K,uang:104527773},
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
How do I iterate through this json message's nested array(i.e. orders) with jquery? [{Type:X,Symbol:AAP,BidPrice:17.0,
I'm having some issues to deserialize a Json array that follows this format: [

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.