我正在做json解析应用程序。其中没有关于解析的问题。我有列表,直到 type =“0”。但是 type =“1”正在进行描述。所有“列表”以及“说明”都已正确设置。
{"pageid":"5824","title":"Sms Collection","type":"0","desc":"Friendship SMS:$@|5825|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Love SMS:$@|5826|@$:4cing.com/mobile_app/uploads/pageicon/Love.png;Miss U SMS:$@|5827|@$:4cing.com/mobile_app/uploads/pageicon/missu.png;Funny SMS:$@|5828|@$:4cing.com/mobile_app/uploads/pageicon/funny.png;Valentine SMS:$@|5829|@$:4cing.com/mobile_app/uploads/pageicon/valantine.png;Adult SMS:$@|5830|@$:4cing.com/mobile_app/uploads/pageicon/adult.png;Anniversary SMS:$@|5832|@$:4cing.com/mobile_app/uploads/pageicon/anniversary.png;Birthday SMS:$@|5833|@$:4cing.com/mobile_app/uploads/pageicon/birthday.png;Break up SMS:$@|5834|@$:4cing.com/mobile_app/uploads/pageicon/Breakup.png;Broken Heart SMS:$@|5835|@$:4cing.com/mobile_app/uploads/pageicon/heartbroken.png;Christmas SMS:$@|5836|@$:4cing.com/mobile_app/uploads/pageicon/Christmas.png;Exam SMS:$@|5837|@$:4cing.com/mobile_app/uploads/pageicon/exam.png;Flirt SMS:$@|5838|@$:4cing.com/mobile_app/uploads/pageicon/flirtsms.png;Good Luck SMS:$@|5839|@$:4cing.com/mobile_app/uploads/pageicon/goodluck.png;Good Morning SMS:$@|5840|@$:4cing.com/mobile_app/uploads/pageicon/goodmornig.png;Good Night SMS:$@|5841|@$:4cing.com/mobile_app/uploads/pageicon/goodnight.png;Insult SMS:$@|5842|@$:4cing.com/mobile_app/uploads/pageicon/inseart.png;Pashto SMS:$@|5843|@$:4cing.com/mobile_app/uploads/pageicon/pashto.png;Poetry SMS:$@|5844|@$:4cing.com/mobile_app/uploads/pageicon/poetry.png;Sardar SMS:$@|5845|@$:4cing.com/mobile_app/uploads/pageicon/sardar.png;Santa Banta SMS:$@|5846|@$:4cing.com/mobile_app/uploads/pageicon/santabanta.png;Smile SMS:$@|5847|@$:4cing.com/mobile_app/uploads/pageicon/smile.png;Sorry SMS:$@|5848|@$:4cing.com/mobile_app/uploads/pageicon/sorry.png;Chanakya SMS:$@|5849|@$:4cing.com/mobile_app/uploads/pageicon/chanakya.png;","cache":"1","Nexturl":"5825","prevurl":"0","bckurl":"0"}
启动应用程序时(type =“0”),这是第一个包含上述数据的列表。
点击友情短信单元格,我得到(type =“0”)此数据。
{"pageid":"5825","title":"Friendship SMS","type":"0","desc":"Do not lie, Do not cheat and do not make promises :$@|5850|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;There are no strings attached to a friendship, no :$@|5851|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;friends are like stars. You ca not always see them:$@|5852|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Friends should b like zero. when u add, they r sam:$@|5853|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Friendship is like a glass handle it with care bec:$@|5854|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;A friend gives hope when life is low, a friend is :$@|5855|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;How long shall we be friends? Do you want a clue? :$@|5856|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;My friendship is nothing but a round, Wandering wh:$@|5857|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;When nails are growing, We cut our nails, Not fing:$@|5858|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;A true friend understands when u say I forgot, wai:$@|5859|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Making a million friends is not an achievement, Th:$@|5860|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Friendship and Medicine both r good 4 our health:$@|5861|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;A memory lasts forever, and never does it die. Tru:$@|5862|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Where there is no compromise in telling the secret:$@|5863|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;I m not Wealthy but i have Rich Heart, I m not Bes:$@|5864|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Do not Love a Friend who Hurts U Do not Hurt a Fri:$@|5865|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;To hear what is unspoken, to see what is invisible:$@|5866|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Life is 5 star Mother is top star Father is king s:$@|5867|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;A single rose can be my garden A single friend, my:$@|5868|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;To live a life i need heartbeat, 2 have heartbeat :$@|5869|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;A true relationship is when you can tell each othe:$@|5870|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Friends\" are like balloons once u let them go u ca:$@|5871|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;MY friendship is just like a rubber band, It is to:$@|5872|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;I wish every relationship come with the same tag a:$@|5873|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;As precious as u r to me, As precious no one can e:$@|5874|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;Friendship Must Never Be Buried Under The Weight O:$@|5875|@$:4cing.com/mobile_app/uploads/pageicon/friendship.png;","cache":"1","Nexturl":"5850","prevurl":"5824","bckurl":"5849"}
最后这个(<=> 1)用于屏幕上点击“别撒谎,不要......” 所以描述显示为
我在后面的过程中遇到问题,我必须使用 prevurl ,这类似于上一页的 pageid ,用于后退功能
这是我正在为后面的功能做的代码,
-(IBAction)btnBackClicked:(id)sender
{
int Type;
NSMutableDictionary *tempDict1;
for(int i=0;i<[test.JsonPageList count];i++)
{
tempDict1 = [[NSMutableDictionary alloc]init];
tempDict1 = (NSMutableDictionary *)[test.JsonPageList objectAtIndex:i];
NSLog(@"pageid is.....%d",[[tempDict1 valueForKey:@"pageid"] intValue]);
if ([[tempDict1 valueForKey:@"pageid"] intValue])
{
Type = [[tempDict1 valueForKey:@"type"] intValue];
if (Type == 0)
{
NSArray *arr=[[tempDict1 valueForKey:@"desc"] componentsSeparatedByString:@";"];
NSString *subStar = @"|@$:";
NSString *sub=@":$@|";
[test.arrTitle removeAllObjects];
[test.arrnew removeAllObjects];
[test.arrId removeAllObjects];
[test.arrImages removeAllObjects];
for (int i=0; i<[arr count]-1; i++)
{
[test.arrTitle addObject:[[arr objectAtIndex:i] substringToIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])-4]];
[test.arrnew addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])]];
[test.arrId addObject:[[test.arrnew objectAtIndex:i] substringToIndex:NSMaxRange([[test.arrnew objectAtIndex:i] rangeOfString:subStar])-4]];
[test.arrImages addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:subStar])]];
}
[tbl_withData reloadData];
}
}
}
}
这是解析的代码
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"SecondTime"])
{
[self saveData:responseData toFile:@"SMSCollection.txt"];
results = [responseString JSONValue];
JsonPageList = [results objectForKey:@"page"];
desc = [[NSMutableArray alloc] init];
for (NSString * strName in results)
{
JsonPageList = [results objectForKey:strName];
dictHash = [[NSMutableDictionary alloc] init];
[dictHash setObject:JsonPageList forKey:@"JsonPageList"];
for (int i = 0; i < [JsonPageList count]; i++)
{
[desc addObject:[[JsonPageList objectAtIndex:i] valueForKey:TAG_DESC]];
int PAGEID = [[NSString stringWithFormat:@"%@",[[JsonPageList objectAtIndex:i] valueForKey:@"pageid"]] intValue];
[self displayPage:PAGEID];
}
}
}
[responseString release];
}
-(void) displayPage:(int)pageID
{
page.pageid = pageID;
if (page.type == PAGE_TYPE_MENU)
{
NSString *desc1=[desc objectAtIndex:0];
NSArray *arr=[desc1 componentsSeparatedByString:@";"];
NSString *subStar = @"|@$:";
NSString *sub=@":$@|";
arrTitle=[[NSMutableArray alloc] init];
arrImages = [[NSMutableArray alloc] init];
arrnew = [[NSMutableArray alloc]init];
arrId=[[NSMutableArray alloc]init];
for (int i=0; i<[arr count]-1; i++)
{
[arrTitle addObject:[[arr objectAtIndex:i] substringToIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])-4]];
[arrnew addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])]];
[arrId addObject:[[arrnew objectAtIndex:i] substringToIndex:NSMaxRange([[arrnew objectAtIndex:i] rangeOfString:subStar])-4]];
[arrImages addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:subStar])]];
}
}
else if (page.type == PAGE_TYPE_CONTENT)
{
NSLog(@"CURR title:- %@\n & desc:- %@",page.title1 ,page.desc);
UITextView *TextView = [[UITextView alloc] init];
TextView.text = page.title1;
UILabel *lblcurrentPage = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
lblcurrentPage.backgroundColor = [UIColor whiteColor];
lblcurrentPage.textColor = [UIColor blackColor];
lblcurrentPage.text = page.desc;
}
}
帮我解决这个问题。