我使用库ObjectMapper将json映射到我的对象,但是我有一些问题要映射根json数组.
这是收到的json:
[
{
CustomerId = "A000015",
...
},
{
CustomerId = "A000016",
...
},
{
CustomerId = "A000017",
...
}
]
Run Code Online (Sandbox Code Playgroud)
这是我的目标
class Customer : Mappable
{
var CustomerId : String? = nil
class func newInstance(map: Map) -> Mappable? {
return Customer()
}
func mapping(map: Map) {
CustomerId <- map["CustomerId"]
}
}
Run Code Online (Sandbox Code Playgroud)
我用我的控制器映射json
let json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as! NSArray
if (error != nil) {
return completionHandler(nil, error)
} else {
var customers = Mapper<Customer>().map(json)
} …Run Code Online (Sandbox Code Playgroud) 我使用a OkHttpClient来下载服务器上的数据库并将其复制到我的Android应用程序上,请求是可以的,我得到了很好的内容.
但是,当我尝试将byteStream我的文件写入我的文件时,我得到了一个java.IOException.closed.你知道我做错了什么吗?
Response httpResponse = webApiClient.execute(
new WebApiRequest(WebApiMethod.DB_DOWNLOAD), context);
if (httpResponse.code() == 200)
{
try
{
InputStream inputStream = httpResponse.body().byteStream();
File databasePath = context.getDatabasePath(Constant.DATABASE_NAME);
FileOutputStream output = new FileOutputStream(databasePath);
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len;
while ((len = inputStream.read(buffer)) != -1)
{
output.write(buffer, 0, len);
}
success = true;
}
catch (Exception exc)
{
Utils.DisplayException(exc, context);
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试ByteStream用a 来读我的BufferedSink但结果是一样的
BufferedSink sink = Okio.buffer(Okio.sink(databasePath));
sink.writeAll(httpResponse.body().source()); …Run Code Online (Sandbox Code Playgroud) 我想StorageFile从路径手动创建 a ,但没有用于StorageFile.
有没有一种简单的方法来做这样的事情?
StorageFile f = new StorageFile("C:\song.mp3");
Run Code Online (Sandbox Code Playgroud)