gpt4 book ai didi

ios - 如何在 iPhone 中使用以下 xml 数据解析数据

转载 作者:行者123 更新时间:2023-11-29 13:11:16 25 4
gpt4 key购买 nike

我是手机编程的新手。我有如下所示的 xml 数据。使用该数据我想显示具有 2 个表的特定日期数据如何在单行中显示特定日期数据。在 2012 年的下一个数据中-06-20 有 3 个表,我如何在第二行显示 3 个表的数据。我如何解析该数据,告诉我它的逻辑

<Result>
<Table diffgr:id="Table1" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T09:01:54-06:00</CafeDateTime>
<CreatedBy>1</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>100.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T10:01:54-06:00</CafeDateTime>
<CreatedBy>1</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>100.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table3" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T09:01:54-06:00</CafeDateTime>
<CreatedBy>2</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>200.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>

</Table> <Table diffgr:id="Table4" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T10:01:54-06:00</CafeDateTime>
<CreatedBy>2</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>200.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table5" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T11:01:54-06:00</CafeDateTime>
<CreatedBy>2</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>200.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table6" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T09:01:54-06:00</CafeDateTime>
<CreatedBy>3</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>150.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table7" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T10:01:54-06:00</CafeDateTime>
<CreatedBy>3</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>150.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Result>


2012-09-19 ->Having 2 tables(i.e Table1,Table2)
2013-09-20 ->Having 3 tables(i.e Table3,Table4,Table5)
2013-09-21 ->Having 2 tables(i.e Table6,Table7)

现在我的问题是在上面的 xml 数据中我在 table1 中共有 7 个表,table2 数据属于 2012-09-19 日期。我想解析数据并在 View 中显示如下所示

                                  CreateBy  SalesDailyAmount  PurchasesDailyAmount
2012-09-19 ->Want to display 1 100 0.0000

使用下面的代码

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
if( [elementName isEqualToString:@"CreateBy"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
xmlResults = YES;
}
if( [elementName isEqualToString:@"SalesDailyAmount"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
xmlResults = YES;
}
if( [elementName isEqualToString:@"PurchasesDailyAmount"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
xmlResults = YES;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( xmlResults )
{
[soapResults appendString: string];
NSLog(@"soap result %@",soapResults);
[arr_detail addObject:soapResults];
NSLog(@"gg %@",arr_detail);
NSLog(@"gcvxg %@",arr_info);
}
[tableView reloadData];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"CreateBy"])
{
xmlResults = FALSE;
[aslam4 addObject:soapResults];
NSLog(@"hello %@",aslam4);
soapResults = nil;
}
if( [elementName isEqualToString:@"SalesDailyAmount"])
{
xmlResults = FALSE;
[aslam5 addObject:soapResults];
NSLog(@"hello %@",aslam5);
soapResults = nil;
}
if( [elementName isEqualToString:@"PurchasesDailyAmount"])
{
xmlResults = FALSE;
[aslam6 addObject:soapResults];
NSLog(@"hello %@",aslam6);
soapResults = nil;
}
}
}

使用上面的代码我可以得到下面这样的数据

 OutPut
CreateBy SalesDailyAmount PurchasesDailyAmount
1 100 0.0000
1 100 0.0000
2 200 0.0000
2 200 0.0000
2 200 0.0000
3 150 0.0000
3 150 0.0000

但是我想在下面这样显示

        CreateBy  SalesDailyAmount  PurchasesDailyAmount
2012-09-19 ->Want to display 1 100 0.0000
2012-09-20 ->Want to display 2 200 0.0000
2012-09-21 ->Want to display 3 150 0.0000

我不想显示多次。在 2012-09-19 有 2 个表,但都有相同的数据,但我不想显示多次。同样,2012-09-20 在这里也有 3 个表,我不想显示 3 次,我想在一行中显示 3 个表数据。总的来说我想说的是现在在数组中存储如下数据Array ={100,100,200,200,200,150,150} 但我不想这样 我想这样存储 Array ={100,200,150}请告诉我如何为此编写逻辑。

最佳答案

为了从数组中获取唯一值,请使用以下方法。

// Your array containing all values
NSArray *dataListArray = [[NSArray alloc] initWithObjects:@"100", @"100", @"200", @"200", @"200", @"300", @"300", @"300", nil];

// Array containing unique data.
NSArray *uniqueDataArray = [[NSSet setWithArray:dataListArray] allObjects];

关于ios - 如何在 iPhone 中使用以下 xml 数据解析数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17324584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com