2012-02-25 1 views
0

привет всем я получаю ниже ответить , когда я использоватькак разобрать данные с помощью json parser после получения ответов?

NSString *jobSearchUrlString = [NSString stringWithFormat:@"http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Countries"]; 
NSLog(@"url for new articles is = %@",jobSearchUrlString); 
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:jobSearchUrlString]]; 

[[NSURLConnection alloc] initWithRequest:request delegate:self]; 
if(request) 
{ 
    RoutData = [[NSMutableData alloc] init]; 

} 
else 
{ 
NSLog(@"RoutConnection is NULL"); 

} 
} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [RoutData setLength: 0]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [RoutData appendData:data]; 
    NSString *thexml = [[NSString alloc] initWithData:RoutData encoding:NSUTF8StringEncoding]; 

NSLog(@">>>>>>>>>> laxman Route data <<<<<<<<<<<<<<<<< %@",thexml); 

xmlParser = [[NSXMLParser alloc] initWithData: RoutData]; 
[xmlParser setDelegate: self]; 
[xmlParser setShouldResolveExternalEntities: YES]; 
[xmlParser parse]; 
result = [soapResults dataUsingEncoding:NSUTF8StringEncoding]; 
webdataParser = [[NSXMLParser alloc]initWithData:result]; 
[webdataParser setDelegate:self]; 
[webdataParser setShouldResolveExternalEntities:YES]; 
[webdataParser parse]; 


NSLog(@"---------->>>>>>>><<<<<<<<<<<--------- %@",resultData); 




<xml version="1.0" encoding="utf-8" standalone="yes"?> 
<feed xml:base="http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> 
    <title type="text">Countries</title> 
    <id>http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Countries</id> 
    <updated>2012-02-25T09:36:30Z</updated> 
    <link rel="self" title="Countries" href="Countries" /> 
    <entry> 
    <id>http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Countries(14)</id> 
    <title type="text"></title> 
    <updated>2012-02-25T09:36:30Z</updated> 
    <author> 
     <name /> 
    </author> 
    <link rel="edit" title="Country" href="Countries(14)" /> 
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Region" type="application/atom+xml;type=entry" title="Region" href="Countries(14)/Region" /> 
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Contact_ 
2012-02-25 15:06:29.393 SampleTest[335:f803] ---------->>>>>>>><<<<<<<<<<<--------- (null) 
2012-02-25 15:06:29.395 SampleTest[335:f803] >>>>>>>>>> laxman Route data <<<<<<<<<<<<<<<<< <?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<feed xml:base="http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> 
    <title type="text">Countries</title> 
    <id>http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Countries</id> 
    <updated>2012-02-25T09:36:30Z</updated> 
    <link rel="self" title="Countries" href="Countries" /> 
    <entry> 
    <id>http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Countries(14)</id> 
    <title type="text"></title> 
    <updated>2012-02-25T09:36:30Z</updated> 
    <author> 
     <name /> 
    </author> 
    <link rel="edit" title="Country" href="Countries(14)" /> 
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Region" type="application/atom+xml;type=entry" title="Region" href="Countries(14)/Region" /> 
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Contact_Country" type="application/atom+xml;type=feed" title="Contact_Country" href="Countries(14)/Contact_Country" /> 
    <category term="HpSalesPortalMobileDBModel.Country" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
    <content type="application/xml"> 
     <m:properties> 
     <d:Id m:type="Edm.Int16">14</d:Id> 
     <d:RegionId m:type="Edm.Byte">1</d:RegionId> 
     <d:CountryName>France</d:CountryName> 
     </m:properties> 
    </content> 
    </entry> 
    <entry> 
    <id>http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Countries(15)</id> 
    <title type="text"></title> 
    <updated>2012-02-25T09:36:30Z</updated> 
    <author> 
     <name /> 
    </author> 
    <link rel="edit" title="Country" href="Countries(15)" /> 

как разобрать данные, чтобы получить «Id», «RegionId» и «COUNTRYNAME». так что любые один помочь мне решить эту проблему в iPhone

привет ваших И хорошо, но дает возможность обработке получить данные для одного элемента является слишком насущным другом

+0

Вашего ответа в XML, а не JSON , поэтому вам нужно использовать синтаксический анализатор XML, а не JSON. Возможно, посмотрите эту ссылку http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project или используйте NSXMLParser – Roger

ответ

1
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 
    //U can Catch Ur data in this delegate And Set Condition Get data Witch U Want. 
}