Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a JSON-based data which contains many fields from a particular model. Any value from the list of fields can be null. I am trying to find the best object oriented way of parsing it and also it has to be light-weighted as it's a mobile application.

PS: Want to avoid numerous "if-checks"

Structure of JSON Data:

data=(          


        classId=""
        classDesc=""
        items=(
            {
                //Array of 50 Items
            },{
                //Array of 50 Items
            },{
                //Array of 50 Items
            }   
        );
    },
   //Remaining Items    
);
share|improve this question
5  
What's your language? What have you tried? That's not correct json. –  Martin Wickman Aug 7 '13 at 6:30
    
Language is Java, "That's not correct json" - I know, just wanted to show the structure of JSON, I'm having. –  user1235555 Aug 7 '13 at 6:50
1  
Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask –  gnat Aug 9 '13 at 8:53
1  
Re: "That's not correct JSON": I agree. It wouldn't have cost you much more effort to write out correct JSON than this pseudo-notation. Like this, your question is just harder to interpret and understand, and thus harder to answer. Since you show us the object structure, you obviously expect us to understand it; but (at least for me) that is not easy at all. Is your {} the same as JSON's []? And is your …=() the same as JSON's …:{}? –  stakx Aug 9 '13 at 8:58

1 Answer 1

Reflection could be used in this situation, you could iterate fields by Class.getFields() method, and set the field flexibly by reflection method in Field Class.

share|improve this answer
    
did you read the question prior to posting? "has to be light-weighted as it's a mobile application" - why do you recommend reflection then? –  gnat Aug 9 '13 at 8:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.