I’m having some difficulties parsing a JSON package in Android.
I currently have everything set up so the JSON is an array of objects, then each object has an array of attributes. For example, say I have an object called Colors in my package. Then each Color entry would be in the Colors object. Each Color entry would also have entries for R, G, B values.
This type, I can deal with fine. However, I’m now running into an instance where one of those entries (where the R,G,B values would be) has an array within it. I’m not sure how to go about accessing that and processing it.
I’m going to update with an example of the JSON package, since I’m worried I wasn’t very clear.
Edit: Here’s the JSON. Say I want to access the R value in the ColorOverlays.
{“Package”:[
{“Things”:[{“ProgramId”:73,”TypeId”:68,”CategoryId”:null,”CategoryName”:null,”ThingId”:121,”ThingName”:”Mahalo”,”ThingDescription”:”Get your festival on and snap some shots!”,”ThingPrice”:0.00,”SellerProductId”:null,”Number2″:1342655700,”Number1″:1342655700,”IsAvailable”:true,”ImageOverlays”:[{“ThingId”:121,”ThingOverlayId”:295,”ImageOverlayBase64″:null,”ImageOverlayFileTypeExtension”:null,”Width”:1024,”Height”:1024,”A”:1.00000,”BlendModeId”:1,”OrderNum”:2,”IsUseSource”:false}],”ColorOverlays”:[{“ThingId”:121,”ThingOverlayId”:294,”R”:157.00000,”G”:71.00000,”B”:187.00000,”A”:0.52873,”BlendModeId”:6,”OrderNum”:1}],”ThingsampleImageBase64″:null,”ThingsampleImageFileTypeExtension”:””,”ThingsampleImageWidth”:546,”ThingsampleImageHeight”:546,”Captures”:[{“ThingCaptureId”:87,”ThingId”:121,”CaptureFrameOverlayId”:null,”IsRemoved”:false,”AddDate”:1342637814,”LastUpdated”:1342637814,”Saturation”:0.0,”Contrast”:0.0,”Brightness”:0.0,”Low”:null,”Mid”:null,”High”:null,”IsBlackWhite”:null,”IsInvert”:null,”IsSepia”:null}],”IsRemoved”:false},{“ProgramId”:73,”TypeId”:68,”CategoryId”:null,”CategoryName”:null,”ThingId”:122,”ThingName”:”Lots of Love”,”ThingDescription”:”Use this one!”,”ThingPrice”:0.00,”SellerProductId”:null,”Number2″:1342667100,”Number1″:1342667100,”IsAvailable”:true,”ImageOverlays”:[{“ThingId”:122,”ThingOverlayId”:298,”ImageOverlayBase64″:null,”ImageOverlayFileTypeExtension”:null,”Width”:1024,”Height”:1024,”A”:1.00000,”BlendModeId”:4,”OrderNum”:3,”IsUseSource”:false}],”ColorOverlays”:[{“ThingId”:122,”ThingOverlayId”:296,”R”:213.00000,”G”:86.00000,”B”:143.00000,”A”:0.77777,”BlendModeId”:4,”OrderNum”:1},{“ThingId”:122,”ThingOverlayId”:297,”R”:127.00000,”G”:127.00000,”B”:127.00000,”A”:0.50000,”BlendModeId”:1,”OrderNum”:2}],”ThingsampleImageBase64″:null,”ThingsampleImageFileTypeExtension”:””,”ThingsampleImageWidth”:546,”ThingsampleImageHeight”:546,”Captures”:[{“ThingCaptureId”:88,”ThingId”:122,”CaptureFrameOverlayId”:null,”IsRemoved”:false,”AddDate”:1342649164,”LastUpdated”:1342649164,”Saturation”:0.0,”Contrast”:0.0,”Brightness”:0.0,”Low”:null,”Mid”:null,”High”:null,”IsBlackWhite”:null,”IsInvert”:null,”IsSepia”:null}],”IsRemoved”:false}]}
]}
If this is not something that you would throw away after the first use, then you might consider taking this up a level by modeling Java objects after your domain.
Use any online JSON visualizer to see your JSON in 3D.
Then, follow the following tutorial.
http://java.sg/parsing-a-json-string-into-an-object-with-gson-easily/