Iphone iOS的复杂JSON响应

Iphone iOS的复杂JSON响应,iphone,objective-c,ios,cocoa,ipad,Iphone,Objective C,Ios,Cocoa,Ipad,我正在使用twitter api的某些部分,并使用ASIHTTPREQUEST获得一些JSON响应。下面是json表示的样子: ( { contributors = "<null>"; coordinates = "<null>"; "created_at" = "Tue Nov 29 15:48:35 +0000 2011"; entities = { has

我正在使用twitter api的某些部分,并使用ASIHTTPREQUEST获得一些JSON响应。下面是json表示的样子:

(
    {
        contributors = "<null>";
        coordinates = "<null>";
        "created_at" = "Tue Nov 29 15:48:35 +0000 2011";
        entities =         {
            hashtags =             (
            );
            media =             (
                                {
                    "display_url" = "pic.twitter.com/650E1WRY";
                    "expanded_url" = "http://twitter.com/ashu1702/status/141544088850796545/photo/1";
                    id = 141544088854990848;
                    "id_str" = 141544088854990848;
                    indices =                     (
                        22,
                        42
                    );
                    "media_url" = "http://p.twimg.com/AfbdmVBCEAAPJvT.jpg";
                    "media_url_https" = "https://p.twimg.com/AfbdmVBCEAAPJvT.jpg";
                    sizes =                     {
                        large =                         {
                            h = 279;
                            resize = fit;
                            w = 215;
                        };
                        medium =                         {
                            h = 279;
                            resize = fit;
                            w = 215;
                        };
                        small =                         {
                            h = 279;
                            resize = fit;
                            w = 215;
                        };
                        thumb =                         {
                            h = 150;
                            resize = crop;
                            w = 150;
                        };
                    };
                    type = photo;
                    url = "http://t.co/650E1WRY";
                }
            );
            urls =             (
            );
            "user_mentions" =             (
            );
        };
        favorited = 0;
        geo = "<null>";
        id = 141544088850796545;
        "id_str" = 141544088850796545;
        "in_reply_to_screen_name" = "<null>";
        "in_reply_to_status_id" = "<null>";
        "in_reply_to_status_id_str" = "<null>";
        "in_reply_to_user_id" = "<null>";
        "in_reply_to_user_id_str" = "<null>";
        place = "<null>";
        "possibly_sensitive" = 0;
        "retweet_count" = 0;
        retweeted = 0;
        source = "<a href=\"http://www.apple.com\" rel=\"nofollow\">iOS</a>";
        text = "I am in Syria @(null) http://t.co/650E1WRY";
        truncated = 0;
        user =         {
            "contributors_enabled" = 0;
            "created_at" = "Sun May 01 15:20:52 +0000 2011";
            "default_profile" = 1;
            "default_profile_image" = 1;
            description = "<null>";
            "favourites_count" = 0;
            "follow_request_sent" = "<null>";
            "followers_count" = 0;
            following = "<null>";
            "friends_count" = 5;
            "geo_enabled" = 0;
            id = 291164338;
            "id_str" = 291164338;
            "is_translator" = 0;
            lang = en;
            "listed_count" = 0;
            location = "<null>";
            name = "Ashutosh Tiwari";
            notifications = "<null>";
            "profile_background_color" = C0DEED;
            "profile_background_image_url" = "http://a0.twimg.com/images/themes/theme1/bg.png";
            "profile_background_image_url_https" = "https://si0.twimg.com/images/themes/theme1/bg.png";
            "profile_background_tile" = 0;
            "profile_image_url" = "http://a2.twimg.com/sticky/default_profile_images/default_profile_3_normal.png";
            "profile_image_url_https" = "https://si0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png";
            "profile_link_color" = 0084B4;
            "profile_sidebar_border_color" = C0DEED;
            "profile_sidebar_fill_color" = DDEEF6;
            "profile_text_color" = 333333;
            "profile_use_background_image" = 1;
            protected = 0;
            "screen_name" = ashu1702;
            "show_all_inline_media" = 0;
            "statuses_count" = 62;
            "time_zone" = "<null>";
            url = "<null>";
            "utc_offset" = "<null>";
            verified = 0;
        };
    }
)
(
{
贡献者=”;
坐标=”;
“创建时间”=“2011年11月29日星期二15:48:35+0000”;
实体={
hashtags=(
);
媒体=(
{
“显示url”=“pic.twitter.com/650E1WRY”;
“扩展的url”=”http://twitter.com/ashu1702/status/141544088850796545/photo/1";
id=14154408854990848;
“id_str”=14154408854990848;
指数=(
22,
42
);
“媒体url=”http://p.twimg.com/AfbdmVBCEAAPJvT.jpg";
“媒体url\U https”=”https://p.twimg.com/AfbdmVBCEAAPJvT.jpg";
尺寸={
大={
h=279;
调整大小=适合;
w=215;
};
中等={
h=279;
调整大小=适合;
w=215;
};
小={
h=279;
调整大小=适合;
w=215;
};
拇指={
h=150;
调整大小=裁剪;
w=150;
};
};
类型=照片;
url=”http://t.co/650E1WRY";
}
);
URL=(
);
“用户提到”=(
);
};
偏爱=0;
geo=“”;
id=14154408850796545;
“id_str”=14154408850796545;
“在屏幕上回复”屏幕名称“=”;
“在对状态的回复中,id=”;
“在对状态的回复中”;
“在对用户id的回复中”=”;
“在答复用户时,用户id字符串=”;
地点=”;
“可能敏感”=0;
“转发计数”=0;
转发=0;
来源=”;
text=“我在叙利亚@(空)http://t.co/650E1WRY";
截断=0;
用户={
“已启用贡献者”=0;
“创建时间”=“2011年5月1日太阳15:20:52+0000”;
“默认_配置文件”=1;
“默认_配置文件_图像”=1;
description=“”;
“收藏夹计数”=0;
“跟随请求发送”=“”;
“追随者数量”=0;
以下为“”;
“朋友数”=5;
“已启用地理位置”=0;
id=291164338;
“id_str”=291164338;
“is_translator”=0;
lang=en;
“列出的计数”=0;
位置=”;
name=“Ashutosh Tiwari”;
通知=”;
“轮廓\背景\颜色”=C0;
“配置文件\u背景\u图像\u url”=”http://a0.twimg.com/images/themes/theme1/bg.png";
“配置文件\u背景\u图像\u url\u https”=”https://si0.twimg.com/images/themes/theme1/bg.png";
“纵断面\背景\平铺”=0;
“配置文件\u图像\u url”=”http://a2.twimg.com/sticky/default_profile_images/default_profile_3_normal.png";
“配置文件\u图像\u url\u https”=”https://si0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png";
“配置文件链接颜色”=0084B4;
“配置文件\侧栏\边框\颜色”=C0;
“纵断面\侧边栏\填充\颜色”=DDEEF6;
“配置文件文本颜色”=333333;
“配置文件\使用\背景\图像”=1;
受保护=0;
“屏幕名称”=ashu1702;
“显示所有内嵌媒体”=0;
“状态计数”=62;
“时区”=“”;
url=“”;
“utc_偏移量”=“”;
验证=0;
};
}
)
这里我关心的是,在实际将整个内容设置为数据模型之前,是否有任何特定的方法将参数设置为空字符串

就像有两个实体“时区”=“”;和“utc_偏移量”=“”;是否仍然需要迭代json响应并设置@“”空字符串。我不想在每个关键点都验证NSNULL特性,它可能会导致我的应用程序在某个点上出现一些循环漏洞,从而导致崩溃,因此我只想弄清楚如何遍历如此复杂的json来检查每个实体,并为NSNULL类型类设置空字符串。我确实尝试过递归方法,但它只给出了上层键的列表,而没有给出字典中的实体


谢谢

不,您必须手动完成。针对
[NSNull null]
进行测试是一条可行之路。

这些
值似乎是字符串,而不是NSNull。如果要将字符串替换为
,则可以使用
stringByReplacingOccurrencesOfstring:withString:
对其进行大规模转换(因为转换您不打算转换的内容存在一定风险)


(但可以肯定的是,如果您提供了一些原始JSON,与NSArray/NSDictionary对象的Objective-C
描述相比,这将是一件好事,这显然就是您正在展示的内容。)

您确定这些行会导致NSNull被反序列化吗?它们似乎是包含的字符串,这对您来说很好,不是吗?@HenriNormak我也这么想,直到我开始通过数据模型将其分配给UITextFields。或者当我在数据模式下分配NSDictionary时