2

これで一日中立ち往生しており、これをできるだけ早く解決するために手を差し伸べてください. どんな助けでも素晴らしいでしょう。ありがとう :-)

欠けている引用符

Web からこの AFJSONRequestOperation リクエストを取得しましたが、1 つの重大な障害を除いてうまく機能します。値がアルファベット順で戻ってくるため、AFNetworking バックグラウンドで何らかの解析が行われていることは明らかです。しかし、私はウェブデータを「そのまま」にしたいだけです...

フォーマットは次のようになります。 theKey = "theValue";

しかし、時々このように見えます。 theKey = theValue; // 値の前後に引用符がないことに注意してください

Web 出力 json:

また、json がサーバーからの正しい形式であることも確認しました。出力は次のようになります。

{"results":[{"ID":"3","Row_state":"Visible","CustName":"Customer Name","CustReferens":"Customer Referens","CustReferensMobil":"123456mob","CustNotes":"Customer Notes","Tel":"123456tel","Fax":"123456fax","Web":"www.example.se","Mail":"info@example.se","Street":"The road 5","Zip":"11122","City":"Stockholm","Products":"","Images":"","Logo":"myLogo.jpg","Text":"A lot of text goese here...","Seller":"","Favorite":"YES"},

アプリでは、この結果が得られます。

results =     (
            {
        City = Stockholm;          // Note the missing quotes around the value
        CustName = "Customer Name";
        CustNotes = "Customer Notes";
        CustReferens = "Customer Referens";
        CustReferensMobil = 123456mob;     // Note the missing quotes around the value
        Favorite = YES;             // Note the missing quotes around the value
        Fax = 123456fax;          // Note the missing quotes around the value
        ID = 3;             // Note the missing quotes around the value
        Images = "";
        Logo = "myLogo.jpg";
        Mail = "info@example.se";
        Products = "";
        "Row_state" = Visible;      // Now key got quotes + Note the missing quotes around the value
        Seller = "";
        Street = "The road 5";
        Tel = 123456tel;         // Note the missing quotes around the value
        Text = "A lot of text goese here...";
        Web = "www.example.se";
        Zip = 11122;       // Note the missing quotes around the value
    },

この予想される結果の代わりに(値を引用符で囲んだすべてのキー);

results =     (
            {
        City = "Stockholm";
        CustName = "Customer Name";
        CustNotes = "Customer Notes";
        CustReferens = "Customer Referens";
        CustReferensMobil = "123456mob";
        Favorite = "YES";
        Fax = "123456fax";
        ID = "3";
        Images = "";
        Logo = "myLogo.jpg";
        Mail = "info@example.se";
        Products = "";
        "Row_state" = Visible;
        Seller = "";
        Street = "The road 5";
        Tel = "123456tel";
        Text = "A lot of text goese here...";
        Web = "www.example.se";
        Zip = "11122";
    },

これに対する私のコード;

NSURL *myUrl = [NSURL URLWithString:@"http://example.se/api.lasso"];
NSURLRequest *request = [NSURLRequest requestWithURL:myUrl];
AFJSONRequestOperation *operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *req, NSHTTPURLResponse *responce, id jsonObject) {
                                            NSLog(@"JSON Responce ÅF: %@",jsonObject);
                                            // Add result (an array from JSON) to NSMutableArray
                                            _restFeed = [jsonObject objectForKey:@"results"];
                                            NSLog(@"RestA-OListTVC > ViewDidload > AFN ÅF: _restFeed count = %i",[_restFeed count]);
                                            // Reload table with new data
                                            [self.tableView reloadData];
                                            }
failure:^(NSURLRequest *req, NSHTTPURLResponse *responce, NSError *error, id jsonObject) {
            NSLog(@"Recieved an HTTP %d", responce.statusCode);
            NSLog(@"The error was: %@",error);
            }];
[operation start];
4

1 に答える 1

3

JSON キーはすべて引用符で囲まれています。これは仕様の一部です。ただし、NSDictionary に変換すると、それらのキーは引用符を失い、オブジェクトになりNSStringます。

JSON {"a": 1}=> Objective-C@{@"a" : @(1)}

NSLog空白を含まない文字列の周りの引用符を取り除きます。NSLog返されるもののリテラル表現としての出力を使用しないでください。期待どおりに値を使用するだけで、valueForKeyPath:すべて正常に機能するはずです。

于 2012-11-02T17:26:19.500 に答える