无法在Parse Data Browser中上传JSON文件

时间:2014-05-30 03:43:50

标签: ios json parse-platform

我在数据浏览器的“文件列”中上传JSON文件时遇到问题

实际上这个上传了

"foo" : [{ "bar": "test", "haha" : "lol" }]

But this can't be uploaded

{ "foo" : [{

 "bar": "test",
 "haha" : "lol"
}] }

我需要第二个格式,因为该格式是有效的JSON格式,并使用AFNetworking的JSON解析器进行解析。

如果我使用第一种JSON格式

,我会遇到此错误
Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x10d4301b0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

已编辑:这是请求的代码

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"the link link to the JSON file" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

    //Do things here with the responseObject

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);

    }];

我实际上是在Parse中将JSON文件上传到数据浏览器中的文件对象。然后我将用AFNetworking来获取它。根据我的观察,具有有效结构的JSON文件无法上传

1 个答案:

答案 0 :(得分:0)

没有代码,评论真的很难。但是,我遇到Cocoa 3840错误的时间是因为我的JSON结构不正确。

这听起来很幼稚,但在这里:

[]表示数组{}表示字典。

我猜,键“foo”与数组有关。当foo包含在{}中时,我认为foo是在NSDictionary中声明的;编码应该像

NSMutableArray *local_array = @[@{@"bar":@"test",@"haha":@"lol"}]
NSDictionary *dict = @{@"foo":local_array};

在此字典上尝试NSJSONSerialization并查看是否发生任何错误