Весь день застрял с этим и протяни руку помощи, чтобы решить эту проблему как можно скорее. Любая помощь будет здорово. Спасибо :-)
Отсутствующие кавычки
Получил этот запрос AFJSONRequestOperation из Интернета, и он отлично работает, за исключением одной важной ошибки: в некоторых ключах отсутствуют кавычки вокруг значений = их нельзя использовать! Очевидно, что в фоновом режиме AFNetworking происходит некоторый синтаксический анализ, поскольку значения возвращаются в алфавитном порядке + «обрезаются» некоторые кавычки для некоторых значений. Но я просто хочу, чтобы веб-данные были "как есть"...
Формат должен выглядеть так: theKey = "theValue";
Но иногда это выглядит так: theKey = theValue; // Обратите внимание на отсутствующие кавычки вокруг значения
Веб-вывод 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":"[email protected]","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 = "[email protected]";
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 = "[email protected]";
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];