java - How I can display the contents of the following json -
i new in android app development. developing android app in need display list of questions 1 after other user of next button. when user clicks next button, next question appears list of options choose from. questions , options retrieved mysql
database php
, response in json
format shown below
{ "questions": [ { "q_id": "18", "qtext": "the largest liability appearing in book of commercial bank is", "option_1": "cash", "option_2": "deposits", "option_3": "loans , advances", "option_4": "capital , reserves", "option_5": "treasury bills" }, { "q_id": "7", "qtext": "a commercial bank unique in institution that", "option_1": "makes loans private people , businessmen", "option_2": "accept deposits", "option_3": "can store peoples' valuables", "option_4": "can transfer money 1 place customers", "option_5": "saves money through granting of credits" }, { "q_id": "3", "qtext": "when elasticity zero, demand curve is", "option_1": "perfectly elastic", "option_2": "perfectly inelastic", "option_3": "concave", "option_4": "downward slopping", "option_5": "circular" }, { "q_id": "5", "qtext": "inferior goods referred in economics goods", "option_1": "whose quality low", "option_2": "consumed poor people", "option_3": "whose consumption falls when consumers' income rises", "option_4": "which satisfy basic needs", "option_5": "none of above" }, { "q_id": "4", "qtext": "the following not reason existence of small firms", "option_1": "scale of production limited size of market", "option_2": "expansion brings diminishing returns", "option_3": "large firms can carter wide markets", "option_4": "small firms can provide personal services", "option_5": "all of above" }, { "q_id": "10", "qtext": "if company doubles inputs , discovers output more doubles, can company experiencing", "option_1": "increasing marginal utility", "option_2": "dis-economies of scale", "option_3": "increasing costs", "option_4": "constant returns scale", "option_5": "increasing returns scale" }, { "q_id": "17", "qtext": "which of following statements true?", "option_1": "a proportional tax 1 takes high income people higher fraction of income takes low income people", "option_2": "taxes on commodities of services can shifted elsewhere called direct taxes", "option_3": "the sole proprietor legal entity", "option_4": "the influence of demand on price smallest on short run", "option_5": "the cost of production important determining factor of supply in long run" }, { "q_id": "1", "qtext": "suppose equilibrium price of article $5.00 government fixes price law @ $4.00, supply be", "option_1": "the same equilibrium supply", "option_2": "greater equilibrium supply", "option_3": "less equilibrium supply", "option_4": "determined later government", "option_5": "none of these" } ], "success": 1 }
please how can display these questions , set of options 1 after other of next button.
i appreciate or if can show me link showing tutorial on how accomplish this. in advance
you can use 1 class question
structure:
class question{ string id; string qtext; string opt1; string opt2; string opt3; string opt4; string opt5; public question (id, ques, opt1, opt2, opt3, opt4, opt5){ this.id = id; this.qtext = ques; this.opt1 = opt1; this.opt2 = opt2; this.opt3 = opt3; this.opt4 = opt4; this.opt5 = opt5; } }
parse response data class as:
list<question> quelist = new arraylist<question>(); jsonarray jarray = new jsonarray(responsestring); int n = jarray.length(); (int = 0; < n; i++) { // individual json object json array jsonobject jo = jarray.getjsonobject(i); // retrieve each json object's fields string id = jo.getstring("id"); string qtext = jo.getstring("qtext"); string opt1 = jo.getstring("option1"); string opt2 = jo.getstring("option2"); string opt3 = jo.getstring("option3"); string opt4 = jo.getstring("option4"); string opt5 = jo.getstring("option5"); question que = new question(id, qtext, opt1, opt2, opt3, opt4, opt5); quelist.add(que); }
so can use list after parsing. hope helps.
Comments
Post a Comment