小编Nic*_*AUX的帖子

iOS - 使用swift中的ObjectMapper映射根JSON数组

我使用库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)

json nsarray ios swift

36
推荐指数
2
解决办法
2万
查看次数

Android OkHttp InputStream java.IOException.closed

我使用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)

java android inputstream okhttp

6
推荐指数
1
解决办法
3526
查看次数

从路径 Win8.1 创建 StorageFile

我想StorageFile从路径手动创建 a ,但没有用于StorageFile.

有没有一种简单的方法来做这样的事情?

StorageFile f = new StorageFile("C:\song.mp3");
Run Code Online (Sandbox Code Playgroud)

c# file windows-8.1

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

标签 统计

android ×1

c# ×1

file ×1

inputstream ×1

ios ×1

java ×1

json ×1

nsarray ×1

okhttp ×1

swift ×1

windows-8.1 ×1