JSON API для Wordpress возвращает беспорядок
Я пытаюсь проанализировать данные JSON, извлеченные из блога Wordpress в Objective C, но они возвращают беспорядок / мусор, который мне не нужен. Например, на главной странице есть 10 сообщений, я могу правильно получить доступ к заголовку и дате публикации, но контент (основная область сообщения) содержит мусор, такой как код для вставки рекламы и т. Д.
Есть ли способ получить данные без беспорядка / мусора?
Вот мой код:
NSURL *blogURL = [NSURL URLWithString:@"http://ioshacker.com/?json=1"];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.posts = [dataDictionary objectForKey:@"posts"];
NSString *title = [[self.posts objectAtIndex:0]valueForKey:@"title_plain"];
NSString *date = [[self.posts objectAtIndex:0]valueForKey:@"date"];
NSString *content = [[self.posts objectAtIndex:0]valueForKey:@"content"];
NSLog(@"%@", title);
NSLog(@"%@", date);
NSLog(@"%@", content);
Вот вывод:
2015-05-24 17:11:31.282 iOSHacker[576:39153] Developing Nuclear Weapons? You might be in breach of iTunes terms and conditions
2015-05-24 17:11:31.283 iOSHacker[576:39153] 2015-05-23 23:50:55
2015-05-24 17:11:31.283 iOSHacker[576:39153]
<!--Ad Injection mfunc mode ad include code--><!--mfunc include_once('/home/thinkios/public_html/wp-content/plugins/ad-injection/adshow.php') --><!--/mfunc-->
<p><a href="http://i2.wp.com/ioshacker.com/wp-content/uploads/2015/05/Nuclear-Weapons-and-Nuclear-Reactors.jpg"><img class="aligncenter size-full wp-image-10887" src="http://i2.wp.com/ioshacker.com/wp-content/uploads/2015/05/Nuclear-Weapons-and-Nuclear-Reactors.jpg?resize=592%2C394" alt="Nuclear-Weapons-and-Nuclear-Reactors" data-recalc-dims="1" /></a></p>
<p>If you are developing Nuclear Weapons in your secret laboratory and using iTunes or related Apple doing while doing it then you are in breach of the iTunes End User License Agreement, no seriously. Apple has made it quite clear in iTunes terms and conditions that you cannot use iTunes or its sub products such as the App Store for development, design, manufacture and production of the nuclear weapons. The company goes one step further by also prohibiting you from developing missiles, chemical and biological weapons using the said software.</p>
<!--Ad Injection mfunc mode ad code--><!--mfunc adshow_display_ad_file_v2(array('ad_random_1.txt'), array(100), array('align' => 'float left', 'clear' => '', 'margin_top' => '0', 'margin_bottom' => '1', 'padding_top' => '1', 'padding_bottom' => '0'), array(), array()) -->
<div style='float:left;margin-top:0px;margin-bottom:1px;padding-top:1px;padding-bottom:0px;margin-right:5px;'><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- iOSHacker above post (top) -->
<ins class="adsbygoogle"
style="display:inline-block;width:336px;height:280px"
data-ad-client=""
data-ad-slot=""></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div><!--/mfunc-->
<p>While we understand the company may have only added this ridiculous clause in iTunes EULA because the government requires them to cover all the basis in their user agreements, but whoever added it must have a wild imagination. Now I am not a scientist who understands Nuclear Physics but I do know that iTunes cannot be used in any way in the production of Nuclear Weapons.</p>
<p>What’s even funnier is that most users who agree to Apple’s terms and conditions never read them. Now just think about what else you have agreed to when you clicked the ‘I Agree’ button the last time.</p>
<p>Here’s the part of <a href="http://www.apple.com/legal/internet-services/itunes/appstore/dev/stdeula/" target="_blank">iTunes EULA</a> clause that talks about Nuclear weapons.</p>
<blockquote><p>“You also agree that you will not use these products for any purposes prohibited by United States law, including, without limitation, the development, design, manufacture or production of nuclear, missiles, or chemical or biological weapons.”</p></blockquote>
1 ответ
Решение
Беспорядок, который вы получаете, является частью JSON, проблем нет. Это часть элемента контента.
В частности содержание: dataDictionary[@"posts"][0][@"content"]
,
Это HTML-контент поста.
Если есть части содержимого, которые вам не нужны, вам придется написать код для удаления этих частей.