在JSON中找到iOS解析img标记
我正试图从下面解析文件位置,以便可以显示图像。我该怎么做在JSON中找到iOS解析img标记,ios,objective-c,Ios,Objective C,我正试图从下面解析文件位置,以便可以显示图像。我该怎么做 [ { "title":"testing barcode display", "body":"lets see if it renders \r\n\r\n", "author":"1", "created":"1373490143", "nid":"5", "Barcode":"<img class=\"barcode\" typeof=\"foaf:Image\" src=\"http://mysite.com/si
[
{
"title":"testing barcode display",
"body":"lets see if it renders \r\n\r\n",
"author":"1",
"created":"1373490143",
"nid":"5",
"Barcode":"<img class=\"barcode\" typeof=\"foaf:Image\" src=\"http://mysite.com/sites/default/files/barcodes/95b2d526b0a8f3860e7309ba59b7ca11QRCODE.png\" alt=\"blahimage\" title=\"blahimage\" />"
}
]
[
{
“标题”:“测试条形码显示”,
“正文”:“让我们看看它是否呈现\r\n\r\n”,
“作者”:“1”,
“已创建”:“1373490143”,
“nid”:“5”,
“条形码”:”
}
]
我有一个显示标题标签的表视图。我需要在详细视图中显示整个内容。除了条形码标签,我什么都能做。请告知。您必须在nsdictionary中转换json字符串,因此请尝试此方法
SBJSON *json = [[SBJSON new] autorelease];
NSError *error;
NSDictionary *dict = [json objectWithString:YOUR_JSON_STRING error:&error];
将用户添加到此词典以在tableView中显示详细信息使用或类似内容
如果您决定使用json框架,下面是如何将json字符串解析为NSDictionary
:
SBJsonParser* parser = [[[SBJsonParser alloc] init] autorelease];
// assuming jsonString is your JSON string...
NSDictionary* myDict = [parser objectWithString:jsonString];
// now you can grab data out of the dictionary using objectForKey or another dictionary method
如果应该这样做,请解析xml
NSString *xmlString = @"<img class=\"barcode\" typeof=\"foaf:Image\" src=\"http://mysite.com/sites/default/files/barcodes/95b2d526b0a8f3860e7309ba59b7ca11QRCODE.png\" alt=\"blahimage\" title=\"blahimage\" />";
GDataXMLElement *xmlElement = [[GDataXMLElement alloc]initWithXMLString:xmlString error:nil];
NSArray *attributes = [xmlElement attributes];
[attributes enumerateObjectsUsingBlock:^(GDataXMLNode * node, NSUInteger idx, BOOL *stop) {
NSLog(@"%@ : %@",node.name,node.stringValue);
}];
给我们一些你自己试图解决这个问题的东西?你有任何选择来改变这个问题的结构吗?混合使用JSON和XML是很困难的。什么样的虐待狂API编写者会这样做?这是JSON,不是免费的。@CodaFi-即使我看到这一点也感到惊讶。API来自drupal服务模块。
NSString *class = [[xmlElement attributeForName:@"class"] stringValue];
NSString *typeOf = [[xmlElement attributeForName:@"typeof"] stringValue];
NSString *src = [[xmlElement attributeForName:@"src"] stringValue];
NSString *alt = [[xmlElement attributeForName:@"alt"] stringValue];
NSString *title = [[xmlElement attributeForName:@"title"] stringValue];