gpt4 book ai didi

iphone - 在 json 解析过程中出现错误

转载 作者:行者123 更新时间:2023-11-28 19:11:44 26 4
gpt4 key购买 nike

我在 json 解析过程中遇到错误。当我尝试使用浏览器发送参数时,它会向我发送成功记录存储的成功消息。但是当我通过 iphone 发送表单参数时,我什么也得不到,在数组中我得到了 NULL 值。这是 json 解析代码。

  NSString *string1 = [[NSString alloc]initWithFormat:@"http://195.78.76.34/bedspace/mobileapi.php?action=save_room_info&Area=%@&Address=%@&Living_room=%@&Amenties=%@&Type_of_cost=%@&cost_of_room=%@&Security_deposit=%@&STLC=%@&Days_available=%@&Bill_included=%@&Broadband_available=%@&Exc_Smoke=%@&Exc_gender=%@&Exc_pets=%@&Exc_age=%@&Exc_language=%@&Exc_nationality=%@&Exc_Sexorientition=%@&Exc_intrest=%@&Pre_smoke=%@&Pre_gender=%@&Pre_occupation=%@&Pre_pets=%@&Pre_min_age=%@&Pre_max_age=%@&Pre_nationaltiy=%@&Pre_Language=%@&Pre_Sexorientition=%@&Misc=%@&Title=%@&Description=%@&Your_name=%@&Your_email=%@&Email_alert=%@&No_of_rooms=%@&Country=%@&City=%@&State=%@&Size_of_property=%@&Type_of_property=%@&Occupets_property=%@&My_property_status=%@&Amenties_two=%@&Size_of_room=%@&Refrence_required=%@",area,address,livingRoomVal,amenties,typeOfCost,costOfRoom,securityDeposit,STLC,daysAvailable,billsIncluded,broadbandAvailable,eSmoke,eGender,ePets,eAge,eLanguage,eNationality,eSexOrientation,eInterest,pSmoke,pGender,pOccupation,pPets,pMinAge,pMaxAge,pNationality,pLanguage,pSexOrientation,misc,title,description,yourName,yourEmail,emailAlerts,noOfRooms,country,city,state,sizeOfProperty,typeOfProperty,occupentsOfProperty,myPropertyStatus,amentiesTwo,sizeOfRoom,refrenceRequired];
NSLog(@"string 1 value %@",string1);
NSURL *urlRequest = [NSURL URLWithString:string1];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:urlRequest];
NSData *dataResponce = [NSURLConnection sendSynchronousRequest:request returningResponse:Nil error:Nil];

NSError *jsonParsingError = nil;
NSArray *publicTimeline = [NSJSONSerialization JSONObjectWithData:dataResponce options:0 error:&jsonParsingError];
NSLog(@"get values %@",publicTimeline);

不知道是什么问题。我还使用了 SBJsonParser 但我在数组中什么也没得到,之后我使用了 NSJSONSerialization 并且同样的问题仍然发生我在 NSData 和 NSArray 中什么也没有。

最佳答案

不能在URL中填入参数还期望它是合法的,所以需要在使用前对URL进行URL编码:

NSURL *urlRequest = [NSURL URLWithString:[string1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

关于iphone - 在 json 解析过程中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14952534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com