所以我使用以下方法从我的iPhone应用程序中的PHP脚本中获取JSON字符串:
NSURL *baseURL = [NSURL URLWithString:@"test.php"];
NSError *encodeError = [[NSError alloc] init];
NSString *jsonString = [NSString stringWithContentsOfURL:baseURL encoding:NSUTF8StringEncoding error:&encodeError];
NSLog(@"Error: %@", [encodeError localizedDescription]);
NSLog(@"STRING: %@", jsonString);
Run Code Online (Sandbox Code Playgroud)
JSON字符串在测试输出时验证.现在我遇到了编码问题.当我获取单个echo'd行时,例如:
{ "testKey":"é" }
Run Code Online (Sandbox Code Playgroud)
JSON解析器工作正常,我能够创建一个有效的JSON对象.但是,当我获取2MB JSON字符串时,我会看到:
Error: Operation could not be completed. (Cocoa error 261.)
Run Code Online (Sandbox Code Playgroud)
和一个空字符串.我的PHP文件本身是UTF8,我没有使用utf8_encode(),因为这似乎是对数据进行双重编码,因为我已经将数据拉为NSUTF8StringEncoding.无论哪种方式,在我的单回显测试中,这是允许我在构建JSON对象时成功记录\ ASDAS样式UTF8转义的方法.
在较大字符串的情况下可能导致错误的原因是什么?
此外,我不确定它是否有所作为,但我在我解析的php数据上使用php函数addslashes()来计算引号等构建JSON字符串时.
在我正在研究的项目中,我有很多使用rakes运行的解析器.当使用已存在于另一个rake中的方法名称,并且因为它们都使用相同的环境时,我会遇到冲突.
有没有办法限制其命名空间中的rake文件的范围?我认为那是命名空间的全部意义吗?
例:
namespace :test do
task :test_task => :environment do
...
end
def test_method(argument)
...
end
end
namespace :other_test do
task :test_task => :environment do
...
end
def test_method(argument, argument2)
...
end
end
Run Code Online (Sandbox Code Playgroud)
在这种情况下,运行时rake test:test_task
我会收到无效数量的参数错误.另一方面,如果我在任务本身内定义方法,我必须按顺序将方法保留在rake文件的顶部.这有点令人困惑和丑陋.
那只是一个必要的邪恶吗?
谢谢!
我正在尝试使用创建一个简单的动画饼图CAShapeLayer
.我想让它从0动画到提供的百分比.
要创建形状图层,我使用:
CGMutablePathRef piePath = CGPathCreateMutable();
CGPathMoveToPoint(piePath, NULL, self.frame.size.width/2, self.frame.size.height/2);
CGPathAddLineToPoint(piePath, NULL, self.frame.size.width/2, 0);
CGPathAddArc(piePath, NULL, self.frame.size.width/2, self.frame.size.height/2, radius, DEGREES_TO_RADIANS(-90), DEGREES_TO_RADIANS(-90), 0);
CGPathAddLineToPoint(piePath, NULL, self.frame.size.width/2 + radius * cos(DEGREES_TO_RADIANS(-90)), self.frame.size.height/2 + radius * sin(DEGREES_TO_RADIANS(-90)));
pie = [CAShapeLayer layer];
pie.fillColor = [UIColor redColor].CGColor;
pie.path = piePath;
[self.layer addSublayer:pie];
Run Code Online (Sandbox Code Playgroud)
然后动画我用:
CGMutablePathRef newPiePath = CGPathCreateMutable();
CGPathAddLineToPoint(newPiePath, NULL, self.frame.size.width/2, 0);
CGPathMoveToPoint(newPiePath, NULL, self.frame.size.width/2, self.frame.size.height/2);
CGPathAddArc(newPiePath, NULL, self.frame.size.width/2, self.frame.size.height/2, radius, DEGREES_TO_RADIANS(-90), DEGREES_TO_RADIANS(125), 0);
CGPathAddLineToPoint(newPiePath, NULL, self.frame.size.width/2 + radius * cos(DEGREES_TO_RADIANS(125)), self.frame.size.height/2 + radius …
Run Code Online (Sandbox Code Playgroud) 这有点基本; 我正在尝试检索iPhone应用程序的http数据.
我有www.myhost.com/test.html
<array><string>test</string><string>test2</string></array>
Run Code Online (Sandbox Code Playgroud)
然后我有
NSURL *baseURL = [NSURLRLWithString:@"http://www.myhost.com/test.html"];
NSArray *array = [NSArray arrayWithContentsOfURL:baseURL];
NSLog(@"%@", [array description]);
Run Code Online (Sandbox Code Playgroud)
哪个继续返回(null).我错过了什么?谢谢!
我有一个模型:
class City
include Mongoid::Document
field :name
embeds_many :stores
index [["stores.location", Mongoid::GEO2D]]
end
class Store
include Mongoid::Document
field :name
field :location, :type => Array
embedded_in :cities, :inverse_of => :stores
end
Run Code Online (Sandbox Code Playgroud)
然后我试着打电话City.stores.near(@location)
.
我想查询City
集合以返回Store
在附近位置至少有1个的所有城市.我该如何设置索引?什么是最快的电话?
我使用Mongoid文档阅读,index [[:location, Mongo::GEO2D]]
但我不确定这是如何应用于嵌入式文档,或者如何只获取City
而不是所有Stop
文档.
我有一个模型,有大约10个属性,我希望JSON
在我的数据库中序列化.
有办法吗?
serialize attribute1, JSON
// ...
serialize attribute10, JSON
Run Code Online (Sandbox Code Playgroud)
一行?因为serialize [attribute1, ..., attribute10], JSON
不起作用.
谢谢!
我的Rails(4.2)应用程序通过Ubuntu(14.02)系统上的Passenger(5.0.28)+ Apache(2.4.7)运行,使用rbenv管理的ruby(2.3.0)。我使用Capistrano(3.4.0)进行部署。
我所有的环境变量都在一个非常简单的profile.d
脚本中设置。
#!/bin/sh
export VAR1=VAL1
export VAR2=VAL2
Run Code Online (Sandbox Code Playgroud)
这就像一个魅力。我的应用程序ENV
具有所有正确的变量,Secrets.yml
并已正确填充...除了通过ssh与Capistrano进行部署外,其他所有功能均正常运行。
在我的deploy.rb
书中,我认为以下内容是相对的:
set :ssh_options, {
forward_agent: true,
paranoid: true,
keys: "~/.ssh/id_rsa.pub"
}
Run Code Online (Sandbox Code Playgroud)
Capistrano文档非常有限,并且ssh \ server配置不是我的强项,我似乎无法弄清楚为什么ENV
Capistrano无法看到我的变量。如果我puts ENV.inspect
在部署流程中运行,则会得到诸如"TERM_PROGRAM"=>"Apple_Terminal"
本地机器用户信息之类的信息。Capistrano为什么不使用远程环境?如何在服务器端或在部署脚本中修改配置以解决此问题?
谢谢您的帮助。
iphone ×3
objective-c ×2
ruby ×2
activerecord ×1
capistrano ×1
cocoa ×1
ios ×1
ipad ×1
json ×1
mongodb ×1
mongoid ×1
passenger ×1
rake ×1
rbenv ×1