2012-02-09 66 views
0

我突然收到以下錯誤。我的應用程序尚未更新,數據庫也沒有更改。我不確定發生了什麼事。
這是我在日誌中得到的錯誤。我將列出xcode項目中的php代碼和導入區域。希望有人會對可能發生的事情有一個想法。MySql數據庫在應用程序內導入錯誤

-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

你看過這些嗎? http://stackoverflow.com/questions/6974863/objective-c-json-unrecognised-leading-character and http://stackoverflow.com/questions/2282778/iphone-objective-c-json-parser – 2012-02-09 17:41:09

回答

0

可能是什麼,但我注意到,你有兩種風格在這裏單引號:

$link = mysql_connect('localhost', ‘username', ‘pass'); 

以前已經咬我。應該是:

$link = mysql_connect('localhost', 'username', 'pass'); 
+0

我有過發生從數據庫中讀取一些東西,我不知道它是如何彈出。我確實修復了這些,我仍然遇到同樣的問題。真奇怪的是,我的知識沒有任何改變。 – 2012-02-09 18:20:48