objective c - iOS use parsed Json and put into TableView -
i'm new both obj-c , json, i'm creating first ios project using tableviewcontroller. json got wcf looks this:
{ fri = ( "\u8fc7\u7a0b\u63a7\u5236\u7cfb\u7edf\u4e0e\u4eea\u8868;\u5468\u4e94\u7b2c1,2\u8282{\u7b2c7-16\u5468};\u9ad8\u5b8f\u4f1f;xx-226", "matlab\u5e94\u7528;\u5468\u4e94\u7b2c3,4\u8282{\u7b2c9-16\u5468};\u8d75\u5ef6\u4e1c;xx-128;;\u8ba1\u7b97\u673a\u8fc7\u7a0b\u63a7\u5236\u6280\u672f;\u5468\u4e94\u7b2c3,4\u8282{\u7b2c1-8\u5468};\u9ad8\u5b8f\u4f1f;xx-226", "\u7f51\u7edc\u5316\u6d4b\u63a7\u7cfb\u7edf;\u5468\u4e94\u7b2c5,6\u8282{\u7b2c1-12\u5468};\u80e1\u745e/\u9648\u4eae;xx-228", "\u5de5\u63a7\u7ec4\u6001\u8f6f\u4ef6\u53ca\u5e94\u7528;\u5468\u4e94\u7b2c7,8\u8282{\u7b2c1-8\u5468};\u9a6c\u666f\u5bcc;xx-228;;\u81ea\u52a8\u63a7\u5236\u539f\u7406\uff08\u63d0\u9ad8\uff09;\u5468\u4e94\u7b2c7,8\u8282{\u7b2c9-16\u5468};\u5218\u6d77\u8273;xx-229", "<null>", "<null>" ); mon = ( "\u5d4c\u5165\u5f0f\u4eea\u8868\u8bbe\u8ba1\u57fa\u7840;\u5468\u4e00\u7b2c1,2\u8282{\u7b2c9-16\u5468};\u5218\u519b/\u77f3\u5f81\u9526;xx-229", "\u7535\u5b50\u6d4b\u91cf\u6280\u672f;\u5468\u4e00\u7b2c3,4\u8282{\u7b2c1-16\u5468};\u8d75\u4e9a\u5a01/\u9ad8\u5b8f\u4f1f;xx-130", "\u4fe1\u53f7\u4e0e\u7cfb\u7edf\uff08\u63d0\u9ad8\uff09;\u5468\u4e00\u7b2c5,6\u8282{\u7b2c1-8\u5468};\u534e\u5b87\u5b81;xx-130;;\u53ef\u7f16\u7a0b\u63a7\u5236\u5668;\u5468\u4e00\u7b2c5,6\u8282{\u7b2c9-16\u5468};\u66f2\u4e07\u6625;xx-336", "\u667a\u80fd\u4eea\u5668\u4eea\u8868;\u5468\u4e00\u7b2c7,8\u8282{\u7b2c1-12\u5468};\u66f2\u4e07\u6625;xx-336", "<null>", "<null>" );}
and did json this:
- (void)viewdidload { [super viewdidload]; self.title = @"jsonread"; nsstring *testurl = @"testurl"; nsurl *url = [nsurl urlwithstring:testurl]; nsurlrequest *request = [[nsurlrequest alloc]initwithurl:url cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:10]; nsdata *jsondata = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; nsarray *jsonresult = [nsjsonserialization jsonobjectwithdata:jsondata options:kniloptions error:nil]; self.str = [[nsstring alloc] initwithdata:jsondata encoding:nsutf8stringencoding]; self.data = jsonresult; nsmutabledictionary *djson = [nsjsonserialization jsonobjectwithdata:jsondata options:nsjsonreadingallowfragments error:nil]; nslog(@"dictionaryjson %@",djson); nsmutablearray *_names=[[nsmutablearray alloc]init]; (id item in jsonresult) [_names addobject:[nsstring stringwithformat:@"%@", item]];; self.names = _names; nslog(@"%@", self.names); }
and comes nsmutablearray names
fri , mon has showed in tableview. wanna ask is, how show other information in tableview well? or how add info nsmutablearray names
? form, lines in different tableview cells, not in same one
fri \u8fc7\u7a0b\u63a7\u5236\u7cfb\u7edf\u4e0e\u4eea\u8868;\u5468\u4e94\u7b2c1,2\u8282{\u7b2c7-16\u5468};\u9ad8\u5b8f\u4f1f;xx-226 matlab\u5e94\u7528;\u5468\u4e94\u7b2c3,4\u8282{\u7b2c9-16\u5468};\u8d75\u5ef6\u4e1c;xx-128
......
mon \u5d4c\u5165\u5f0f\u4eea\u8868\u8bbe\u8ba1\u57fa\u7840;\u5468\u4e00\u7b2c1,2\u8282{\u7b2c9-16\u5468};\u5218\u519b/\u77f3\u5f81\u9526;xx-229 u7535\u5b50\u6d4b\u91cf\u6280\u672f;\u5468\u4e00\u7b2c3,4\u8282{\u7b2c1-16\u5468};\u8d75\u4e9a\u5a01/\u9ad8\u5b8f\u4f1f;xx-130
......
thanks much, post pics if could, can't...sorry that...and answers
also, didn't mean xxx,xxxx
show in 1 row... want them show in different tableviewcells if possible, or show in different rows in 1 cells if there's no better solution. adding them single nsstring isn't solution i'm looking for... sorry
try below solution..
for (id item in jsonresult) { nsarray *array=[jsonresult valueforkey:item]; nsstring *joinedcomponents = [array componentsjoinedbystring:@","]; [_names addobject:[nsstring stringwithformat:@"%@ %@", item,joinedcomponents]];; self.names = _names; nslog(@"%@", self.names); }
hope helps you..!
Comments
Post a Comment