我正在使用以下代码将InputStream转换为JSONObject.我的问题是,是否有任何简单的方法将InputStream转换为JSONObject.不做InputStream - > BufferedReader - > StringBuilder - > loop - > JSONObject.toString().
InputStream inputStreamObject = PositionKeeperRequestTest.class.getResourceAsStream(jsonFileName);
BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStreamObject, "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
responseStrBuilder.append(inputStr);
JSONObject jsonObject = new JSONObject(responseStrBuilder.toString());
Run Code Online (Sandbox Code Playgroud) 我很难理解Objective C中动态绑定Vs动态类型之间的区别.有人可以解释一下吗?
我想添加两个编译器标志,一个用于ARC(-fno-objc-arc),另一个用于警告(-w).有人知道如何在特定文件的Xcode构建阶段添加两个编译器标志吗?
输入字符串:2012年6月14日 - 01:00:00 UTC
输出本地字符串:美国东部时间2012年6月13日 - 21:00:00
我喜欢从中获得偏移
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSLog(@"Time Zone: %@", destinationTimeZone.abbreviation);
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
有3种(我知道)抑制"未使用的变量"警告的方法.任何特定方式都比其他方式更好?
第一
- (void)testString:(NSString *)testString
{
(void)testString;
}
Run Code Online (Sandbox Code Playgroud)
第二
- (void)testString:(NSString *)__unused testString
{
}
Run Code Online (Sandbox Code Playgroud)
第三
- (void)testString:(NSString *)testString
{
#pragma unused(testString)
}
Run Code Online (Sandbox Code Playgroud) 我在我的Android应用程序中使用GSON来解析数据.我在我的Model对象中添加了一个枚举.添加枚举后,我的应用程序开始崩溃.当我创建runProguard时,一切正常.当程序成立时,我做了我在互联网上找到的所有解决问题的方法.但仍然没有运气.
我已经在proguard规则文件中做了以下事情
-keep class com.google.** { *; }
-keepattributes *Annotation*
-keepattributes Signature
-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
Run Code Online (Sandbox Code Playgroud)
Enum Stuff示例:
public enum TypeX {
@SerializedName("live")
LIVE,
@SerializedName("upcoming")
UPCOMING,
@SerializedName("replay")
REPLAY; }
Run Code Online (Sandbox Code Playgroud)
我的堆栈跟踪
java.lang.AssertionError
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>(Unknown Source)
at com.google.gson.internal.bind.TypeAdapters$26.create(Unknown Source)
at com.google.gson.Gson.getAdapter(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(Unknown Source)
at com.google.gson.Gson.getAdapter(Unknown Source)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(Unknown Source)
at com.google.gson.Gson.getAdapter(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(Unknown Source)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(Unknown …Run Code Online (Sandbox Code Playgroud) 我正在尝试UIWebView使用Facebook OAuth授权URL 加载,我使用以下代码.当我UIWebView加载Facebook登录页面时,我输入我的凭据,然后按"登录"按钮.当我按下按钮时,我收到以下错误:
WebKit在webView中丢弃了一个未捕获的异常:decisionPolicyForNavigationAction:request:frame:decisionListener:delegate:Application试图以模态方式呈现一个活动的控制器.
这个相同的代码适用于iOS 4.3和以前的版本,但它在iOS 5.0中不起作用.我不明白这个问题,有人可以帮帮我吗?
NSString *redirectUrlString = @"http://www.facebook.com/connect/login_success.html";
NSString *authFormatString = @"https://graph.facebook.com/oauth/authorize?client_id=%@&redirect_uri=%@&scope=%@&type=user_agent&display=touch";
NSString *urlString = [NSString stringWithFormat:authFormatString, _apiKey, redirectUrlString, _requestedPermissions];
NSURL *url = [NSURL URLWithString:urlString];
NSLog(@"NSURL: %@", urlString);
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
Run Code Online (Sandbox Code Playgroud) 我从以下代码获取"未使用的参数'testString'"警告.但我使用testString来记录.那怎么没用呢?
- (void)getString:(NSString *)testString {
ICELogInfo(@"%@", testString);
}
Run Code Online (Sandbox Code Playgroud)
ICELogInfo是NSLog的宏.
#define ICELogInfo(fmt, ...) LOG_FORMAT(fmt, @"INFO", ##__VA_ARGS__)
#define LOG_FORMAT(fmt, lvl, ...) LOG_FORMAT_NO_LOCATION(fmt, lvl, ##__VA_ARGS__)
#define LOG_FORMAT_NO_LOCATION(fmt, lvl, ...) NSLog((@"%@ " fmt), lvl, ##__VA_ARGS__)
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
+ (NSArray *)systemLogDictionariesForAppName:(NSString *)appName {
aslmsg q = asl_new(ASL_TYPE_QUERY);
asl_set_query(q, ASL_KEY_SENDER, [appName cStringUsingEncoding:NSASCIIStringEncoding], ASL_QUERY_OP_EQUAL);
aslresponse r = asl_search(NULL, q);
aslmsg m;
uint32_t i;
const char *key, *val;
NSMutableArray *systemLogDictionaries = [NSMutableArray array];
while (NULL != (m = aslresponse_next(r)))
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
for (i = 0; (NULL != (key = asl_key(m, i))); i++)
{
val = asl_get(m, key);
NSString *stringKey = [NSString stringWithCString:key encoding:NSUTF8StringEncoding];
NSString *stringVal = [NSString stringWithCString:val encoding:NSUTF8StringEncoding];
[dictionary setObject:stringVal forKey:stringKey];
}
[systemLogDictionaries addObject:dictionary];
}
aslresponse_free(r); …Run Code Online (Sandbox Code Playgroud) 有什么方法可以在NSCache中存储结构值?当我阅读Apple文档时,您似乎只能将AnyObject存储到其中。围绕几个工作,一个是将sturct转换为类,第二是将sturct值转换为字典,但是如果数据集很大,它们的操作将非常昂贵。有什么建议吗?