在ios7此代碼的工作,但現在我得到的錯誤: - [__ NSCFString objectForKeyedSubscript:]:無法識別的選擇發送到實例獲取代碼「無法識別的選擇發送到實例」爲iOS8上
.m文件
//get the JSON response
NSDictionary *jsonData = [NSJSONSerialization
JSONObjectWithData:urlData
options:NSJSONReadingMutableContainers
error:&error];
//Parses the "success" value
success = [jsonData[@"success"] integerValue];
//Was it successful?
if(success){
//successful, save the profile gathered into global gMyProfile
NSArray *profileJSON=jsonData[@"myProfile"];
for (NSDictionary* dict in profileJSON)
{
NSLog(@"First_Name: %@", dict [@"first_name"]);
...
錯誤發生在NSLog聲明上,並且來自一點研究,它抱怨字典[@「first_name」]);
login.py
....
#Query for user
db_cursor = db.cursor(MySQLdb.cursors.DictCursor)
db_query = """SELECT users.email, users.first_name, users.profile_pic_path, \
FROM users,data WHERE users.email='%s' \
AND users.user_id=data.user_id""" % user_email
db_cursor.execute(db_query)
#If there is one record containing the username check password
if(db_cursor.rowcount == 1):
user_profile = db_cursor.fetchone()
...
json_obj= {'success': 1, 'myProfile': user_profile,}
...
JSON輸出:
{'myProfile': {'first_name': 'Matt', 'email': '[email protected]', 'profile_pic_path': 'default'}, 'success': 1}
所有這些代碼是工作,我沒有改變任何東西。 任何幫助將不勝感激!!!!
沒有看到JSON,我們不能做太多。 – 2014-09-26 17:18:16
用JSON輸出編輯帖子:) – lr100 2014-09-26 17:26:44
轉到json.org並研究JSON語法。學習只需要5-10分鐘。然後回到這裏並解釋你的代碼是如何構成的。 – 2014-09-26 17:37:57