我突然收到以下错误。我的应用尚未更新,数据库也未更改。我不确定发生了什么事 这是我在日志中得到的错误。我将列出PHP代码和xcode项目中的导入区域。希望有人能够了解可能发生的事情。
-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x911e5c0 {NSLocalizedDescription=Unrecognised leading character}"
)
//php code
<?php
$link = mysql_connect('localhost', ‘username', ‘pass');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("thedb");
$action = $_GET['action'];
if(!empty($action)) {
if($action == 'listquote') {
$result = mysql_query("SELECT * FROM quote ORDER BY id DESC");
$rows = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if($row)
$rows[] = $row;
}
echo json_encode($rows);
}
}
mysql_close($link);
?>
DataImportOperation
- (NSError *)processData:(NSData *)content{
NSString *result = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding];
NSArray *arrayList = [result JSONValue];
[result release];
result = nil;
NSString *filePath = [CWAppSettings pathDicData];
//NSMutableDictionary *dictWrite = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSMutableDictionary *dictWrite = [[NSMutableDictionary alloc] init];
NSMutableArray *plistArray = [[NSMutableArray alloc] init];
NSArray *allValues = [dictWrite objectForKey:@"Quotes"];
if ([allValues count] > 0) {
for (NSArray *temp in allValues) {
[plistArray addObject:temp];
}
}
NSAutoreleasePool *aPool = [[NSAutoreleasePool alloc] init];
long long timestamp = 0;//= [[plistArray objectForKey:@"timestamp"] longLongValue];
for (NSDictionary *dict in arrayList) {
if ([dict objectForKey:@"quote"] != nil) {
NSString *quote = [dict objectForKey:@"quote"];
if ([[NSString stringWithFormat:@"%@", quote] isEqualToString:@"<null>"]) continue;
NSString *idQuote = [dict objectForKey:@"id"];
NSArray *array = [NSArray arrayWithObjects:idQuote,quote, nil];
[plistArray addObject:array];
DLog(@"%@", quote);
}
}
[dictWrite setValue:plistArray forKey:@"Quotes"];
[dictWrite writeToFile:filePath atomically:YES];
if (timestamp != 0) {
[CWAppSettings setLastUpdate:timestamp];
}
if (self.delegate && [self.delegate respondsToSelector:@selector(retrieveListOperationDidFinishImportingData)]) {
[self.delegate retrieveListOperationDidFinishImportingData];
}
if (dictWrite != nil) {
[dictWrite release];
dictWrite = nil;
}
if (plistArray != nil) {
[plistArray release];
plistArray = nil;
}
if (aPool != nil){
[aPool release];
aPool = nil;
}
return nil;
}
就像我说的那样......它很奇怪,因为它突然停止了工作。我不确定可能会有什么变化。内容仍在数据库中。
答案 0 :(得分:0)
可能一点都没有,但我注意到你有两种风格的单引号:
$link = mysql_connect('localhost', ‘username', ‘pass');
之前曾经咬过我的话。应该是:
$link = mysql_connect('localhost', 'username', 'pass');