gpt4 book ai didi

iphone - iOS 的复杂 JSON 响应

转载 作者:行者123 更新时间:2023-11-29 11:18:12 25 4
gpt4 key购买 nike

我正在使用 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;
};
}
)

这里我关心的是,在真正将整个内容设置为数据模型之前,有没有具体的方法可以将参数设置为空字符串?

就像有两个实体一样 "time_zone"= "";和“utc_offset”=“”;无论如何要遍历 json 响应并设置 @""空字符串。我不想在每个关键点都验证 NSNULL 功能,它可能会导致我的应用程序在某些时候出现一些循环漏洞而崩溃,因此我只想弄清楚如何遍历如此复杂的 json 来检查每个实体并为 NSNull 类型类设置空字符串。我确实尝试过递归方式,但它只给出了上层键的列表,而不是字典中的实体。

谢谢

最佳答案

"<null>"值似乎是字符串,而不是 NSNulls。如果要将字符串替换为"" , 你可以使用 stringByReplacingOccurrencesOfstring:withString:大量转换它们(因为存在转换您不打算转换的内容的风险)。

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

关于iphone - iOS 的复杂 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8482056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com