小编JuJ*_*oDi的帖子

如何使用NSJSONSerialization从JSON对象获取值

我可以检索JSON对象并显示它,但是如何从"lat"和"lng"中获取值以在Xcode中使用?

我的代码:

NSString *str=[NSString stringWithFormat:@"https://www.<WEBSITE>];
NSURL *url=[NSURL URLWithString:str];
NSData *data=[NSData dataWithContentsOfURL:url];
NSError *error=nil;

NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:data
                                                           options:kNilOptions
                                                             error:&error];
NSLog(@"Your JSON Object: %@ Or Error is: %@", dictionary, error);
Run Code Online (Sandbox Code Playgroud)

JSON对象:

(
    {
    response =         {

        lat = "52.517681";
        lng = "-115.113995";

    };
}
Run Code Online (Sandbox Code Playgroud)

)

我似乎无法访问任何数据.我试过了:

NSLog(@"Value : %@",[dictionary objectForKey:@"response"]);
Run Code Online (Sandbox Code Playgroud)

我也尝试了很多变化

NSLog(@"Value : %@",[[dictionary objectForKey:@"response"] objectForKey:@"lat"]);
Run Code Online (Sandbox Code Playgroud)

但它总是以崩溃告终:

-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15dd8b80
Run Code Online (Sandbox Code Playgroud)

我注意到,当我进行调试时,'字典'只包含1个对象.如何将我的JSON对象转换为具有密钥对的NSDictionary?这个JSON对象是错误的格式还是什么?

json objective-c nsdictionary

4
推荐指数
1
解决办法
8727
查看次数

Mongoose - 查找其数组属性包含给定子集的所有文档?

我有一个基于以下架构的(简化的)模型:

schema = mongoose.Schema({
    foo: { type: String },
    bars: [{ type: String }]
});
model = mongoose.model ('model', schema);
Run Code Online (Sandbox Code Playgroud)

我想创建一个 API 来返回包含逗号分隔列表中提供的所有“条”的所有文档。所以我有:

exports.findByBars = function (req, res) {
  var barsToFind = req.body.bars.split(',');
  // find the matching document
};
Run Code Online (Sandbox Code Playgroud)

Mongoose 是否为此提供了 API,或者是否有一个查询参数可以传递给 Model#find 来获取此功能?我只希望当文档的 bar 属性包含数组中的所有值时返回该文档barsToFind

mongoose mongodb node.js

4
推荐指数
1
解决办法
4160
查看次数

swift 中的 Sink 协议是什么?

Swift 标头将 Sink 协议定义为

protocol Sink {
    typealias Element
    func put(x: Element)
}
Run Code Online (Sandbox Code Playgroud)

什么是 Sink 协议,关于 Swift 和 Cocoa 设计模式,它应该用于什么?

我能说的唯一实现这个协议的是

struct IntEncoder : Sink {
    var asInt: UInt64
    var shift: UInt64
    func put(x: CodeUnit)
}
Run Code Online (Sandbox Code Playgroud)

swift

4
推荐指数
1
解决办法
1501
查看次数

使用telnet通过C++中的TCP/IP与QNX Neutrino进行通信

我可以通过PuTTY访问telnet服务器,它打开一个终端,允许我发送命令来检索数据/日志和启动/停止进程.我想开始研究如何通过C++访问这个服务器,以便自动化连接和测试命令.基本上我需要一个telnet客户端,它可以连接和验证自己,并且可以像写入终端一样在服务器上写入和读取.我应该在哪里开始我的研究?我尝试了几个例子,包括:

http://lists.boost.org/boost-users/att-40895/telnet.cpp

当我编译并运行时

./telnet 192.168.1.26 23
Run Code Online (Sandbox Code Playgroud)

什么都没发生,但当我用PuTTY连接到服务器时,我得到:

QNX Neutrino (localhost) (ttyp0)

login: root  
password:  
#  
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.
注意:
- 我正在使用运行OS X版本10.7.3的Mac和i686-apple-darwin11-llvm-gcc-4.2
- 我被允许这样做.
- 我在Windows 7机器上使用PuTTY,连接是以太网到USB以太网适配器,本地连接属性> TCP/IPv4属性的设置:是特定的IP地址,子网掩码和默认网关,可能是有用的信息.

谢谢

c++ client tcp telnet qnx-neutrino

3
推荐指数
1
解决办法
4638
查看次数

无法分配给'let'值'action'

我正在尝试在switch语句之外定义一个常量,以便我可以在switch语句执行完毕后使用它并在switch语句中分配它:

let action: SKAction!

switch (whatever) {
case 0:
    sprite.position = CGPointMake(0, self.scene.size.height * lengthDiceroll)
    action = SKAction.moveTo(CGPointMake(self.scene.size.width, self.scene.size.height * (1 - lengthDiceroll)), duration: 1) // error here
    // other actions
default:
    println("meh")       

// add the sprite to the scene
let sequence = SKAction.sequence([action, action2])
sprite.runAction(SKAction.repeatActionForever(sequence))
self.addChild(sprite)
Run Code Online (Sandbox Code Playgroud)

但是我收到了错误Cannot assign to 'let' value 'action'.如何分配操作以便我可以在交换机外部使用它?

如果我尝试:

action! = SKAction.moveTo(CGPointMake(self.scene.size.width, self.scene.size.height * (1.0 - lengthDiceroll)), duration: 1)
Run Code Online (Sandbox Code Playgroud)

我收到了错误"Could not find an overload for '*' that accepts the supplied arguments".

constants switch-statement swift

3
推荐指数
1
解决办法
4720
查看次数

Swift:if let 语句中的条件类型转换(as?,as!)

如果基类有多种可能性,建议将“as”与“if”结合使用的方法是什么,例如

var delegate:AnyObject?

func myFunction(){

if let delegate = self.delegate as? A1ViewController {
  delegate.callFunction()
}

if let delegate = self.delegate as? A2ViewController{
   delegate.callFunction()
}
}
Run Code Online (Sandbox Code Playgroud)

有没有办法将上面的两个 if 语句结合起来?

例如

if let delegate = self.delegate as? A1ViewController || let delegate = self.delegate = self.delegate as? A2ViewController {
   delegate.callFunction()
}
Run Code Online (Sandbox Code Playgroud)

swift

3
推荐指数
1
解决办法
1508
查看次数

以20s延迟调用的多重方法中的代码

我正在使用多重连接,这是方法之一:

-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress

{
NSLog(@"RECEIVING... %@ from peer: %@", progress, peerID);

UIProgressView *progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressBar.frame = CGRectMake(0, 200, 100, 20);
progressBar.progress = 0.5;
UIButton* btn = [BluetoothDeviceDictionary objectForKey:peerID];
[self.view addSubview:progressBar];

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Alert View Title" message:@"Alert View Text" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
}
Run Code Online (Sandbox Code Playgroud)

由于某些非常严重的原因,当调用此方法时,我知道由于NSLog的响应而调用它,其余代码不会被执行.NSLog出现后,警报显示20秒(或多或少),并且进度视图永远不会出现.我不明白为什么.对于多重连接框架中的大多数方法都会发生这种情况.这怎么可能?

编辑:实际上进度视图出现了,但是在调用方法之后出现了很多

uikit ios multipeer-connectivity

2
推荐指数
1
解决办法
955
查看次数

NSJSONSerialization - 为dataWithJSONObject指定没有NSJSONWritingOptions的正确值是什么:options:error:?

Apple的文档包含NSJSONWritingOptions枚举,其中定义了一个常量:NSJSONWritingPrettyPrinted,并说"如果未设置此选项,则会生成最紧凑的可能JSON表示."

我绝对想要最紧凑的JSON表示.

我的问题是:传递dataWithJSONObject的正确值是什么:options:error:function如果我不想打印漂亮,为什么?

NSJSONWritingOptions枚举定义为

enum {     NSJSONWritingPrettyPrinted = (1UL << 0) }; typedef NSUInteger NSJSONWritingOptions;
Run Code Online (Sandbox Code Playgroud)

我在一篇不同的帖子中读过0应该通过,但没有进一步的解释为什么它不应该是零.

enums objective-c nsjsonserialization

2
推荐指数
1
解决办法
2458
查看次数

使用Multipeer Connectivity跟踪NSProgress中的更改

我使用多重连接在蓝牙上发送文件.进度存储在名为Progress的变量中:

NSProgress* progress;
Run Code Online (Sandbox Code Playgroud)

并以这种方式访问​​它:

progress.fractionCompleted
Run Code Online (Sandbox Code Playgroud)

当数字发生变化时,如何调用方法来更新我的UIprogressBar?

有一种方法:

-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress

{
NSLog(@"RECEIVING... %@ from peer: %@", progress, peerID);

}
Run Code Online (Sandbox Code Playgroud)

但它只被召唤一次......

ios multipeer-connectivity

2
推荐指数
1
解决办法
1571
查看次数

找不到pthread_cancel用android工具链编译

我正在编译一个使用Android工具链配​​置的程序.我正在使用ndk r10c.我使用了一个独立的工具链

$./make-standalone-toolchain.sh --ndk-dir=/home/justin/bin/android-ndk-r10c/ --install-dir=/home/justin/android-toolchain/
Run Code Online (Sandbox Code Playgroud)

并能够配置我的项目,但是当make我得到

error: 'pthread_cancel' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

标题有#include <pthread.h>,这个答案似乎表明我应该像往常一样使用pthreads.

我错过了什么吗?

pthreads cross-compiling android-ndk

2
推荐指数
1
解决办法
1814
查看次数