Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS5 JSON解析与子级_Iphone_Json_Ios5 - Fatal编程技术网

Iphone iOS5 JSON解析与子级

Iphone iOS5 JSON解析与子级,iphone,json,ios5,Iphone,Json,Ios5,我尝试用iOS5解析Json提要 我的Json文件如下所示: { "status": "ok", "count": 18, "count_total": 2248, "pages": 125, "posts": [ { "id": 31781, "type": "post", "slug": "aaa", "url": "http:\/\/www.example.com\/videos\/aaa.html", "

我尝试用iOS5解析Json提要

我的Json文件如下所示:

{
  "status": "ok",
  "count": 18,
  "count_total": 2248,
  "pages": 125,
"posts": [
    {
      "id": 31781,
      "type": "post",
      "slug": "aaa",
      "url": "http:\/\/www.example.com\/videos\/aaa.html",
      "status": "publish",
      "title": "my Title",
      "title_plain": "My Title",
      "content": "<p>Jdfkdfkjkjdfklfdkldfkldfklfkdld.<\/p>\n",
      "excerpt": "Jdfkdfkjkjdfklfdkldfkldfklfkdlds.",
      "date": "2012-01-26 07:38:29",
      "modified": "2012-01-26 07:38:29",
      "categories": [
        {
          "id": 4,
          "slug": "videos",
          "title": "Videos",
          "description": "",
          "parent": 0,
          "post_count": 476
        }
      ],
      "tags": [],
      "author": {
        "id": 4,
        "slug": "author",
        "name": "Au Thor",
        "first_name": "",
        "last_name": "",
        "nickname": "Au Thor",
        "url": "",
        "description": ""
      },
      "attachments": [
        {
          "id": 31784,
          "url": "http:\/\/www.example.com\/wp-content\/uploads\/2012\/01\/primo.jpg",
          "slug": "primo",
          "title": "primo",
          "description": "",
          "caption": "",
          "parent": 31781,
          "mime_type": "image\/jpeg",
          "images": {
            "full": {
              "url": "http:\/\/www.example.com\/wp-content\/uploads\/2012\/01\/primo.jpg",
              "width": 620,
              "height": 389
            },
            "thumbnail": {
              "url": "http:\/\/www.example.com\/wp-content\/uploads\/2012\/01\/primo-150x75.jpg",
              "width": 150,
              "height": 75
            },
            "medium": {
              "url": "http:\/\/www.example.com\/wp-content\/uploads\/2012\/01\/primo.jpg",
              "width": 620,
              "height": 389
            },
            "large": {
              "url": "http:\/\/www.example.com\/wp-content\/uploads\/2012\/01\/primo.jpg",
              "width": 620,
              "height": 389
            }
          }
        }
      ],
      "comment_count": 1,
      "comment_status": "open",
      "thumbnail": "http:\/\/www.example.com\/wp-content\/uploads\/2012\/01\/primo-150x75.jpg"
    },
NSArray* latestArticles = [json objectForKey:@"posts"];
NSDictionary* Article = [latestArticles objectAtIndex:0];
NSString *Titre = [Article objectForKey:@"title"];
但是我怎样才能访问attachement>image>full>url字段呢

我迷路了,新的JSON


谢谢你的帮助,

我还没有测试过,但我相信会的

NSArray *allPosts = [json objectForKey:@"posts"];
NSDictionary *firstPost = [allPosts objectAtIndex:0];
NSArray *allAttachments = [firstPost objectForKey:@"attachments"];
NSDictionary *firstAttachment = [allAttachments objectAtIndex:0];
NSDictionary *allImages = [firstAttachment objectForKey:@"images"];
NSDictionary *fullImage = [allImages objectForKey:@"full"];
NSString *urlString = [fullImage objectForKey:@"url"];

使用
NSJSONSerialization
如果看到
[]
对象将是
NSArray
,如果看到
{}
对象将是
NSDictionary

你也可以通过

NSArray *posts=json[@"posts"];
NSDictionary *newArticle=posts[0];
NSString *title=newArticle[@"title"];
记住Objective-c实际上是具有面向对象概念的c语言。您也可以应用基本c代码或基本c语法。:)