Question

i've this unique text plain

{"id":"AALI.NG","data":["AALI","NG",19312,0,0,0,0,0,0,0,0,0,0,0,70,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"AALI.RG","data":["AALI","RG",19500,0,0,0,0,0,0,0,0,0,0,0,26,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"AALI.TN","data":["AALI","TN",19500,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABBA.NG","data":["ABBA","NG",60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABBA.RG","data":["ABBA","RG",85,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABBA.TN","data":["ABBA","TN",85,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABDA.NG","data":["ABDA","NG",3500,0,0,0,0,0,0,0,0,0,0,0,6000,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}

then i change it to :

 {"stockQuote":[{"id":"AALI.NG","data":["AALI","NG",19312,0,0,0,0,0,0,0,0,0,0,0,70,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"AALI.RG","data":["AALI","RG",19500,0,0,0,0,0,0,0,0,0,0,0,26,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"AALI.TN","data":["AALI","TN",19500,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABBA.NG","data":["ABBA","NG",60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABBA.RG","data":["ABBA","RG",85,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABBA.TN","data":["ABBA","TN",85,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABDA.NG","data":["ABDA","NG",3500,0,0,0,0,0,0,0,0,0,0,0,6000,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}]}

basicly type of data i get from server is text/plain and i need to add {"stockQuote":[, "," and also }]} to make it like json...

the question is, how to parse it to json an NSMutableArray then i draw it to UITableView, how to do it?? should i change it to NSDictionary first and then insert it to NSMutableArray?

Was it helpful?

Solution

Your second JSON is just an NSDictionary with a single object that is an NSArray. So just take your normal array that you have in the first JSON, and do this:

NSArray *jsonArray = [jsonDic objectForKey:@"stockQuote"];

where jsonDic is your json's parse object with NSJSONSerialization method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top