ios - AFNetworking 获取 json 值并将其保存为 NSMutablearray
<p><p>我是 ios 及其开发的新手。我有正确设置的干净代码 <code>AFNetworking</code>。我的基本 URl 的 json Encording 有 JSON 对象和数组以及值。在我的 JSON 输出中,我想在每次获取 Null 时获取“缩略图”的值。请帮助我获取我的 json 输出的“名称、缩略图、id、图像”。请找到我的 NSDictionary 类型打印对象的 NSlog。</p>
<pre><code>2014-07-20 09:08:33.110 WADTourisum Reachability Flag Status: -R ------- networkStatusForFlags
2014-07-20 09:08:33.879 WADTourisum JSON: {
Main = (
{
id = 1;
"image_bundle_id" = 1;
images = (
"http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/1.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/2.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/oceans/slide_images/3.jpg"
);
name = OCEAN;
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/ocean.jpg";
},
{
id = 2;
"image_bundle_id" = 23;
images = (
"http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/1.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/2.jpg",
"http://wearedesigners.net/clients/clients12/tourism/images/guides/heritages/slide_images/3.png"
);
name = Heritage;
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/heritage.jpg";
},
{
id = 3;
"image_bundle_id" = 0;
images = (
);
name = "Tea Country";
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/teaCountry.jpg";
},
{
id = 4;
"image_bundle_id" = 0;
images = (
);
name = "WILD LIFE";
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/wildLife.jpg";
},
{
id = 5;
"image_bundle_id" = 0;
images = (
);
name = Culture;
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/culture.jpg";
},
{
id = 6;
"image_bundle_id" = 0;
images = (
);
name = "NIGHT LIFE";
thumbnail = "http://wearedesigners.net/clients/clients12/tourism/images/guides/thumbs/nightLife.jpg";
}
);
</code></pre>
<p>}</p>
<p>我的代码片段</p>
<pre><code>-(void) retriveData
{
AFHTTPRequestOperationManager *manager = ;
[manager GET:@"http://www.fr20.wearedesigners.net/WADMac/tourism/fetchGuideListAndroid.php"
parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.posts =(NSDictionary *)responseObject;
self.post =self.posts[@"thumbnail"];
NSLog(@"JSON: %@", self.post);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *alertView = [ initWithTitle:@"Please log into internetet"
message:
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
;
}];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您收到了响应,我看到的唯一问题是您无法正确检索值。</p>
<p>在从 JSON 中获取数据时,请记住获取数据的格式,即获取数组或字典。</p>
<p>看到您的回复,您将获得本身包含字典的 Array。</p>
<p>使用以下代码获取值</p>
<pre><code>NSArray *array = ;
for (NSDictionary *dict in array) {
NSInteger ids = [ integerValue];
NSString *name = ;
NSString *thumbnail = ;
NSArray *arrImages = ;
//You can use them accordingly
}
</code></pre>
<p>希望这对您有所帮助。快乐编码:) </p></p>
<p style="font-size: 20px;">关于ios - AFNetworking 获取 json 值并将其保存为 NSMutablearray,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24850911/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24850911/
</a>
</p>
页:
[1]