- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将我保存在 UserDefaults 上的 Twitter 提要传递给 WebService。 WebService 有效,因为我在传递来自 Facebook 的提要时使用它。
- (void) fetchedTwitterFeeds: (NSString *)screenname{
STTwitterAPI * twit = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:twitter_id consumerSecret:twitter_secret];
if ([[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_SCREEN_NAME] !=nil) {
screenname = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_SCREEN_NAME]];
}
[twit verifyCredentialsWithSuccessBlock:^(NSString * username){
[twit getUserTimelineWithScreenName:screenname successBlock:^(NSArray * statuses){
self.feeds = [NSMutableArray arrayWithArray:statuses];
NSLog(@"Twitter Feeds Login: %@", feeds);
NSLog(@"Session Token: %@", [[NSUserDefaults standardUserDefaults] valueForKey:SESSION_TOKEN]);
NSLog(@"Track ID: %d", track_id);
NSLog(@"Tweets: %@", [feeds valueForKey:@"text"]);
NSLog(@"Created at: %@", [feeds valueForKey:@"created_at"]);
NSLog(@"Country: %@", [[feeds valueForKey:@"place"] valueForKey:@"country"]);
NSLog(@"Place Name: %@", [[feeds valueForKey:@"place"] valueForKey:@"full_name"]);
NSLog(@"Sample Lat: -75.14310264");
NSLog(@"Sample Long: 40.05701649");
NSLog(@"Media URL: %@", [[[feeds valueForKey:@"entities"] valueForKey:@"media"] valueForKey:@"media_url"]);
NSLog(@"Provider Name: %@", TWITTER_PROVIDER);
//Saving Feeds
if ([feeds valueForKey:@"text"] !=nil)[[NSUserDefaults standardUserDefaults] setObject:[feeds valueForKey:@"text"] forKey:TWITTER_FEED_TWEETS_KEY];
else[[NSUserDefaults standardUserDefaults] setObject:@"No Tweets" forKey:TWITTER_FEED_TWEETS_KEY];
if ([feeds valueForKey:@"created_at"] !=nil)[[NSUserDefaults standardUserDefaults] setObject:[feeds valueForKey:@"created_at"] forKey:TWITTER_FEED_DATE_CREATED_KEY];
else[[NSUserDefaults standardUserDefaults] setObject:@"No Date Created" forKey:TWITTER_FEED_DATE_CREATED_KEY];
if ([feeds valueForKey:@"created_at"] !=nil)[[NSUserDefaults standardUserDefaults] setObject:[[feeds valueForKey:@"place"] valueForKey:@"country"] forKey:TWITTER_FEED_COUNTRY_KEY];
else[[NSUserDefaults standardUserDefaults] setObject:@"No Country" forKey:TWITTER_FEED_COUNTRY_KEY];
if ([feeds valueForKey:@"created_at"] !=nil)[[NSUserDefaults standardUserDefaults] setObject:[[feeds valueForKey:@"place"] valueForKey:@"full_name"] forKey:TWITTER_FEED_PLACE_NAME_KEY];
else[[NSUserDefaults standardUserDefaults] setObject:@"No Place Name" forKey:TWITTER_FEED_PLACE_NAME_KEY];
if ([feeds valueForKey:@"created_at"] !=nil)[[NSUserDefaults standardUserDefaults] setObject:@"-75.14310264" forKey:TWITTER_FEED_LATITUDE_KEY];
if ([feeds valueForKey:@"created_at"] !=nil)[[NSUserDefaults standardUserDefaults] setObject:@"40.05701649" forKey:TWITTER_FEED_LONGITUDE_KEY];
if ([feeds valueForKey:@"created_at"] !=nil)[[NSUserDefaults standardUserDefaults] setObject:[[[feeds valueForKey:@"entities"] valueForKey:@"media"] valueForKey:@"media_url"] forKey:TWITTER_FEED_MEDIA_URL_KEY];
else[[NSUserDefaults standardUserDefaults] setObject:@"No Media " forKey:TWITTER_FEED_MEDIA_URL_KEY];
}errorBlock:^(NSError * error){
NSLog(@"%@", error.debugDescription);
}];
}errorBlock:^(NSError * error){
NSLog(@"%@", error.debugDescription);
}];
}
这是我在 NSLog(@"Twitter Feeds Login: %@", feeds) 时得到的 Twitter Feeds:
2014-08-19 15:42:10.497 backtrack[11009:60b] Twitter Feeds Login: (
{
contributors = "<null>";
coordinates = "<null>";
"created_at" = "Tue Aug 19 04:50:45 +0000 2014";
entities = {
hashtags = (
);
media = (
{
"display_url" = "pic.twitter.com/kKBrsjf4GO";
"expanded_url" = "http://twitter.com/calsofer/status/501592079156273152/photo/1";
id = 501592077608562689;
"id_str" = 501592077608562689;
indices = (
5,
27
);
"media_url" = "http://pbs.twimg.com/media/BvYDVkgCMAEBucu.png";
"media_url_https" = "https://pbs.twimg.com/media/BvYDVkgCMAEBucu.png";
sizes = {
large = {
h = 120;
resize = fit;
w = 120;
};
medium = {
h = 120;
resize = fit;
w = 120;
};
small = {
h = 120;
resize = fit;
w = 120;
};
thumb = {
h = 120;
resize = crop;
w = 120;
};
};
type = photo;
url = "http://t.co/kKBrsjf4GO";
}
);
symbols = (
);
urls = (
);
"user_mentions" = (
);
};
"extended_entities" = {
media = (
{
"display_url" = "pic.twitter.com/kKBrsjf4GO";
"expanded_url" = "http://twitter.com/calsofer/status/501592079156273152/photo/1";
id = 501592077608562689;
"id_str" = 501592077608562689;
indices = (
5,
27
);
"media_url" = "http://pbs.twimg.com/media/BvYDVkgCMAEBucu.png";
"media_url_https" = "https://pbs.twimg.com/media/BvYDVkgCMAEBucu.png";
sizes = {
large = {
h = 120;
resize = fit;
w = 120;
};
medium = {
h = 120;
resize = fit;
w = 120;
};
small = {
h = 120;
resize = fit;
w = 120;
};
thumb = {
h = 120;
resize = crop;
w = 120;
};
};
type = photo;
url = "http://t.co/kKBrsjf4GO";
}
);
};
"favorite_count" = 0;
favorited = 0;
geo = "<null>";
id = 501592079156273152;
"id_str" = 501592079156273152;
"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>";
lang = en;
place = {
attributes = {
};
"bounding_box" = {
coordinates = (
(
(
"-8.662663",
"49.1626564"
),
(
"1.768926",
"49.1626564"
),
(
"1.768926",
"60.86165"
),
(
"-8.662663",
"60.86165"
)
)
);
type = Polygon;
};
"contained_within" = (
);
country = "United Kingdom";
"country_code" = GB;
"full_name" = "United Kingdom";
id = 6416b8512febefc9;
name = "United Kingdom";
"place_type" = country;
url = "https://api.twitter.com/1.1/geo/id/6416b8512febefc9.json";
};
"possibly_sensitive" = 0;
"retweet_count" = 0;
retweeted = 0;
source = "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>";
text = "Test http://t.co/kKBrsjf4GO";
truncated = 0;
user = {
"contributors_enabled" = 0;
"created_at" = "Sat Jan 29 11:30:22 +0000 2011";
"default_profile" = 0;
"default_profile_image" = 0;
description = "You can't just grow a sexy beard. You either have one, or you don't..:";
entities = {
description = {
urls = (
);
};
};
"favourites_count" = 0;
"follow_request_sent" = "<null>";
"followers_count" = 17;
following = "<null>";
"friends_count" = 47;
"geo_enabled" = 1;
id = 244472426;
"id_str" = 244472426;
"is_translation_enabled" = 0;
"is_translator" = 0;
lang = en;
"listed_count" = 0;
location = "";
name = "Christopher Fuertes";
notifications = "<null>";
"profile_background_color" = 1A1B1F;
"profile_background_image_url" = "http://pbs.twimg.com/profile_background_images/558638885/559647_3164538518462_1415356240_32122022_1669491008_n.jpg";
"profile_background_image_url_https" = "https://pbs.twimg.com/profile_background_images/558638885/559647_3164538518462_1415356240_32122022_1669491008_n.jpg";
"profile_background_tile" = 1;
"profile_banner_url" = "https://pbs.twimg.com/profile_banners/244472426/1352679509";
"profile_image_url" = "http://pbs.twimg.com/profile_images/2838158026/56ed90e6ccc6c35cc41a1a8a41db312e_normal.jpeg";
"profile_image_url_https" = "https://pbs.twimg.com/profile_images/2838158026/56ed90e6ccc6c35cc41a1a8a41db312e_normal.jpeg";
"profile_link_color" = 960E20;
"profile_sidebar_border_color" = FFFFFF;
"profile_sidebar_fill_color" = 252429;
"profile_text_color" = 666666;
"profile_use_background_image" = 1;
protected = 0;
"screen_name" = calsofer;
"statuses_count" = 1;
"time_zone" = "Kuala Lumpur";
url = "<null>";
"utc_offset" = 28800;
verified = 0;
};
}
)
这是我将其传递给网络服务的代码:
NSLog(@"UserDefault Tweets: %@", [[NSUserDefaults standardUserDefaults] objectForKey:TWITTER_FEED_TWEETS_KEY]);
NSLog(@"UserDefault Date Created: %@", [[NSUserDefaults standardUserDefaults] objectForKey:TWITTER_FEED_DATE_CREATED_KEY]);
NSLog(@"UserDefault Country: %@", [[NSUserDefaults standardUserDefaults] objectForKey:TWITTER_FEED_COUNTRY_KEY]);
NSLog(@"UserDefault Place Name: %@", [[NSUserDefaults standardUserDefaults] objectForKey:TWITTER_FEED_PLACE_NAME_KEY]);
NSLog(@"UserDefault Latitude: %@", [[NSUserDefaults standardUserDefaults] objectForKey:TWITTER_FEED_LATITUDE_KEY]);
NSLog(@"UserDefault Longtitude: %@", [[NSUserDefaults standardUserDefaults] objectForKey:TWITTER_FEED_LONGITUDE_KEY]);
NSLog(@"UserDefault Media URL: %@", [[NSUserDefaults standardUserDefaults] objectForKey:TWITTER_FEED_MEDIA_URL_KEY]);
NSDictionary * dict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObjects: [[NSUserDefaults standardUserDefaults] valueForKey:SESSION_TOKEN], [NSString stringWithFormat:@"%d", track_id], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_TWEETS_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_DATE_CREATED_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_COUNTRY_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_PLACE_NAME_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_LATITUDE_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_LONGITUDE_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_MEDIA_URL_KEY],TWITTER_PROVIDER, nil]
forKey:[NSArray arrayWithObjects:SESSION_TOKEN, @"track_id", @"message",@"date_created",@"country",@"place_name",@"latitude",@"longitude",@"media_url",@"provider_name", nil]];
[webService postRequestFromUrl:[NSString stringWithFormat:@"%@%@", ROOT_SERVER_URL, SAVE_DATA_FEEDS] withDictionary:dict];
但我在这样做时遇到了错误。错误是:
最佳答案
当你创建 dict
时,你应该使用 dictionaryWithObjects:forKeys:
,而不是 dictionaryWithObject:forKey:
- 你正在指定 NSArray
作为您的键,异常告诉您,它不是字符串。
你应该有 -
NSDictionary * dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [[NSUserDefaults standardUserDefaults] valueForKey:SESSION_TOKEN], [NSString stringWithFormat:@"%d", track_id], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_TWEETS_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_DATE_CREATED_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_COUNTRY_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_PLACE_NAME_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_LATITUDE_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_LONGITUDE_KEY], [[NSUserDefaults standardUserDefaults] valueForKey:TWITTER_FEED_MEDIA_URL_KEY],TWITTER_PROVIDER, nil]
forKeys:[NSArray arrayWithObjects:SESSION_TOKEN, @"track_id", @"message",@"date_created",@"country",@"place_name",@"latitude",@"longitude",@"media_url",@"provider_name", nil]];
如果您只是将变量设置为 [NSUserDefaults standardUserDefaults]
并引用它而不是重复调用 standardUserDefaults
方法,您的代码也会更容易阅读
关于ios - 将数据传递到 Web 服务时出错。 'NSInvalidArgumentException' , 原因 : 'Invalid (non-string) key in JSON dictionary' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25380806/
我正在使用 gmock 并模拟了一个函数 boost::beast::http::response_parser作为输出参数。功能签名看起来像: error_code readFromSocket(b
我的任务是打印由“非元音、元音、非元音”组成的单词列表,即 bab、bac、bad、bad ... 到 zuz。 我已经设法创建了一个代码,它执行前两个字母,但在最后一个循环中丢失并只打印'}' -
我正在尝试使用 label2rgb 生成 RGB 标签切片并使用它来更新 RGB 体积,如下所示: labelRGB_slice=label2rgb(handles.label(:,:,han
我有一个很奇怪的问题。我在 dll 中定义了一个接口(interface),如下所示: public interface IKreator2 { string Name { get; set;
在我的 openshift Drupal 托管中,网络都在 SSL 下 http://domain.com -> https://www.domain.com 确定 http://www.domain
我收到警告“退出构造函数时不可为空的事件‘SomeEvent’必须包含非空值。考虑将事件声明为可空。” 这是我的代码的一个非常简化的版本,它复制了完全相同的问题。我在这里错过了什么?这与 .Net 6
在一次大学考试中,我被要求测试一些 apache 簿记员类/方法,在这样做的过程中,我想在我的参数化测试中使用 mockito。没有 mockito 的测试工作正常但是当我尝试模拟接口(interfa
假设 A 列在 7 行中有以下值: 2 [空白的] 0 -0.3 0 [空白的] 0 如何获取范围(7 行)中非空/空白且不为零的最后一个值?因此,在这种情况下,正确答案是 -0.3。 最佳答案 =I
考虑以下受 this talk 启发的代码: template struct even_common_type_helper_impl; template struct even_common_typ
考虑这段代码, struct A {}; struct B { B(const A&) {} }; void f(B) { cout << "f()"<
考虑下面的类(class)。如果我对它运行 Findbugs,它会在第 5 行但不在第 7 行给我一个错误(“可序列化类中的非 transient 非可序列化实例字段”)。 1 public clas
我正在编写一个 python 脚本来计算 数据包丢失 通过使用 ping IP 地址linux 中的 subprocess 模块。 CSV 文件中保存了多个 IP 地址。当只给出可 ping 目的地时
我只是做文本更改,在文本之前它工作正常。请任何人都可以帮助我。 提前致谢 最佳答案 我已经解决了: ionic cordova 插件rmcordova-plugin-ionic-webview ion
我如何定义 在 persistence.xml 中? 我的项目在 Tomcat 6 和 Tomcat 7 中运行良好。 现在我正在使用 Struts 2 Spring 3.0.5 JPA 2 Jbos
我有一个 maven 仓库中不存在的第三方 jar,我们称它为“a.jar”,它也依赖于至少 20 多个第三方 jar,其中大部分不在 maven 中或者,我们称它们为“b.jar、c.jar、d.j
我已经浏览了各种线程很多小时(不夸张),但一直无法找到一种解决方案组合,使我能够将非 www 和 http 转发到 www 和 https,同时仍然能够查看 php 文件没有扩展名。如下是我的ngin
Scott Meyer 关于非成员函数增加封装并允许更优雅的设计(设计方面)的论点对我来说似乎非常有效。看这里:Article 但是我对此有疑问。 (似乎还有其他人,尤其是库开发人员,他们通常完全忽略
在对类设计的一些事实感到困惑时,特别是函数是否应该是成员,我查看了 Effective c++ 并找到了第 23 条,即 Prefer non-member non-friend functions
我正在尝试使用 firebase 云功能将通知发送到一个点半径的圆内的设备。我能够获取圈内设备的 ID,但无法获取 token ,使用 console.log(token) 打印时 token 为空。
我在我的项目中使用 React-ckeditor 5 包。我得到一个反序列化的 html 数据,我正在使用 React-html-parser 包将它解析成 html 模板,并将这个解析的数据传递给
我是一名优秀的程序员,十分优秀!