1

这是我的 xml 文件的示例

<TheamName>
    <item1>Green</item1>
    <item2>Blue</item2>
</TheamName>

<FontName>
    <item1>دعاء</item1>
    <item2>دعاء</item2>
    <item3>دعاء</item3>
    <item4>دعاء</item4>
</FontName>

但是当我试图解析这个有这个响应时

{
    item1 = Green;
    item2 = Blue;
},
    {
    item1 = "\U062f\U0639\U0627\U0621";
    item2 = "\U062f\U0639\U0627\U0621";
    item3 = "\U062f\U0639\U0627\U0621";
    item4 = "\U062f\U0639\U0627\U0621";
}

尝试在 json 上转换它,然后尝试响应但没有成功,它也给出了相同的结果。

请告诉我如何取回原始的不同语言字符串?

提前Thakas寻求帮助!

编辑

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *theXML = [[[NSString alloc] initWithBytes:[arrXmlData mutableBytes] length:[arrXmlData length] encoding:NSUTF8StringEncoding] autorelease];

CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:[theXML dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil] autorelease];

arrSession = [[NSMutableArray alloc] init];

NSArray *nodesLibRateEstimate = [doc nodesForXPath:@"//Headings" error:nil];
for (CXMLElement *node in nodesLibRateEstimate) {
    NSMutableDictionary *dictData=[[NSMutableDictionary alloc]init];
    for(int counter = 0; counter < [node childCount]; counter++) {
        if ([[[node childAtIndex:counter] name] isEqualToString:@"app_name"]) {
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"app_name"];
        }else if([[[node childAtIndex:counter] name] isEqualToString:@"action_settings"]){
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"action_settings"];
        }
    }
    [arrSession addObject:dictData];
}

NSArray *nodesLibOriginatingServiceCenter = [doc nodesForXPath:@"//TheamName" error:nil];
for (CXMLElement *node in nodesLibOriginatingServiceCenter) {
    NSMutableDictionary *dictData=[[NSMutableDictionary alloc]init];
    for(int counter = 0; counter < [node childCount]; counter++) {
        if ([[[node childAtIndex:counter] name] isEqualToString:@"item1"]) {
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"item1"];
        } else if ([[[node childAtIndex:counter] name] isEqualToString:@"item2"]) {
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"item2"];
        }
    }
    [arrSession addObject:dictData];
}

NSArray *nodesLibOriginatingServiceCenter2 = [doc nodesForXPath:@"//FontName" error:nil];
for (CXMLElement *node in nodesLibOriginatingServiceCenter2) {
    NSMutableDictionary *dictData=[[NSMutableDictionary alloc]init];
    for(int counter = 0; counter < [node childCount]; counter++) {
        if ([[[node childAtIndex:counter] name] isEqualToString:@"item1"]) {
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"item1"];
        } else if ([[[node childAtIndex:counter] name] isEqualToString:@"item2"]) {
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"item2"];
        } else if ([[[node childAtIndex:counter] name] isEqualToString:@"item3"]) {
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"item3"];
        } else if ([[[node childAtIndex:counter] name] isEqualToString:@"item4"]) {
            NSString *strValue;
            if ([[[node childAtIndex:counter] stringValue]isEqualToString:@""] || [[node childAtIndex:counter] stringValue]==nil) {
                strValue=@"";
            }else{
                strValue=[self trimString:[[node childAtIndex:counter] stringValue]];
            }
            [dictData setObject:strValue forKey:@"item4"];
        }
    }
    [arrSession addObject:dictData];
}

NSLog(@"The arrSession is :%@",arrSession);

[connection release];
[arrXmlData release];
}
4

1 回答 1

1

您的回答是正确
的,而不是在数组中打印,而是尝试单独打印。

例如

NSLog(@"%@", [[arrSession objectAtIndex:1] objectForKey:@"item1"]);

假设你的

{
    item1 = "\U062f\U0639\U0627\U0621";
    item2 = "\U062f\U0639\U0627\U0621";
    item3 = "\U062f\U0639\U0627\U0621";
    item4 = "\U062f\U0639\U0627\U0621";
}

在索引1arrSession

于 2013-09-17T10:06:18.990 回答