Tag: json

特殊字符JSON iOS SQLite

我有一个问题。 我从JSON获取信息,他返回我无效的字符。 JSON给我这个:“27 /”“当我需要这个:27”。 我知道这是一个特殊字符的编码,但是当我使用NSString的值在SQLite表中创build一个插入,我不能使用27 /“原因插入格式是这样的:INSERT INTO FORMATOS(ID,NOMBRE)VALUES (“17”,“27”“)。 我需要什么方法在SQLlite中正确插入信息? for (int i = 0; i<idFormato.count; i++) { NSString *idStr = [idFormato objectAtIndex:i]; NSString *nameStr = [nameFormato objectAtIndex:i]; insertSQL = [NSString stringWithFormat:@"INSERT INTO FORMATOS (ID, NOMBRE) VALUES (\"%@\", \"%@\")", idStr, nameStr]; //Char constant with the query encoded un UTF const char *insert_stmt = [insertSQL UTF8String]; […]

带“(”“)”括号的JSON不是“”

在.m中: @implementation ViewController { NSDictionary *_json; } – (void)viewDidLoad { [super viewDidLoad]; NSURL* url = [NSURL URLWithString:@"http://api.worldweatheronline.com/free/v1/weather.ashx?q=Si%C3%B3fok&format=json&num_of_days=5&key=mykey"]; NSData *jsonData = [NSData dataWithContentsOfURL:url]; NSError *error; _json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; NSDictionary* fullDictFromjson = _json[@"data"]; NSLog(@"%@",fullDictFromjson); NSDictionary* currentCondition = fullDictFromjson[@"current_condition"]; NSLog(@"%@",currentCondition); 在这之后,我在Console(currentCondition)中得到了这个: 2013-04-18 22:18:16.758 weather[18111:c07] ( { cloudcover = 0; humidity = 74; "observation_time" = "08:18 […]

将自定义对象序列化为包含NSMutableArray的JSON

我想序列化我的Cart对象,它有一个NSMutableArray的项目,但得到一个: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (Item)' 如果我理解这应该如何工作,我需要创build一个字典数组,以便NSJSONSerialization正常工作。 这不是我在下面做什么? 我的Cart.h: @interface Cart : BaseObject @property (nonatomic, strong) NSString *comp; @property (nonatomic, strong) NSString *sono; @property (nonatomic, strong) NSString *cust; @property (nonatomic, strong) NSString *scus; @property (nonatomic, strong) NSString *cnid; @property (nonatomic, strong) NSString *dldt; @property (nonatomic, […]

select器视图iPhone的JSON数组

我从JSON Web服务获取这些数据 List ARRAY: ( { assets = ( { identity = 34DL3611; systemId = 544507; }, { identity = 34GF0512; systemId = 5290211; }, { identity = 34HH1734; systemId = 111463609; }, { identity = 34HH1736; systemId = 111463622; }, { identity = 34YCJ15; systemId = 294151155; } ); identity = DEMO; systemId = […]

parsing目标C中的纯JSON数组

我想parsing一个普通的JSON数组,如: { "ns": [ [ "1364987475027", "Alert1", "001" ], [ "1364987475042", "Alert2", "001" ], [ "1364987475058", "Alert4", "001" ] ] } 以简单的string数组获取数组。 我发现有很多JSON字典数组的post。 但在这种情况下,JSON不具有值的键。 请帮助。

wsdl2swift只有结果为零,连接结果OK

我正在使用http://wsdl2swift.com/创build一个调用asmx-WebService的iOS Swift JSON客户端。 一切都很好,我可以build立连接,在响应XML中接收结果JSON-String,并将其打印在库“makeSoapConnection”函数中。 但是,如果我打电话 let client = SyedAbsarClient() let gam = GetAllBla() gam.cpMyId = "12" client.opGetAllBla(gam){(response: GetAllBlaResponse?, error:NSError?) -> Void in print(response?.cpGetAllBlaResult) } 我只得到“n”

在iOS中parsing图像下载的多部分响应

在我的应用程序中,我从服务器下载图像作为多部分内容。 在我的回复数据中,我得到了2个部分:一个是json内容,另一个是下载的文件。 回应的格式如下。 –poa89012-3212-1232-9201-fdsakjkj921 Content-Type: application/json; charset=utf-8 Content-Disposition: inline; name=info { //json content } –poa89012-3212-1232-9201-fdsakjkj921 Content-Disposition: file; name=file; filename=photo.png Content-Type: application/octet-stream // File data ˘íë77íí77Í¥2008:02:11 11:32:512008:02:1 —— 我无法处理这个有2个部分的响应,当我尝试在didReceiveResponse中获取标题时:它给出了内容types为multipart / mixed的整个响应的标题。请向我展示处理此响应的方法通过分裂json内容和文件内容。

NSURLErrorDomain错误代码1002说明

我是iOS开发新手。 我想加载一个JSON ,这是我的function: func loadmyJSON (urlPath: String) { let url: NSURL = NSURL(string: urlPath)! let session = NSURLSession.sharedSession() let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in println("Task completed") if(error != nil) { // If there is an error in the web request, print it to the console println("error not nil::::::") println(error.localizedDescription) } […]

Objective-C / iOS:将对象数组转换为JSONstring

我目前正在尝试使用JSON进行互联网数据传输。 我已经成功接收JSONstring并将其转换为NSDictionary ,但还没有能够解决如何将对象的数组或字典转换为JSON表示。 我已经阅读了大量的文章和文章,解释如何创build一个键/值对的NSDictionary ,然后转换为JSON,这对于一个简单的数组工作正常,但是当你有一个数组或对象的字典时,如何实现这一点。 所以,例如,我有一个对象“联系”的数组,然后我想转换成一个JSONstring,如下所示: "contacts":{ "contact":[ { "id":"1" "first_name":"john", "last_name":"citizen", "phone":"9999 9999" } { "id":"1" "first_name":"jane", "last_name":"doe", "phone":"8888 8888" } ] } 我有一个NSMutableDictionary填充联系人对象列表: NSMutableDictionary* contactsToBeSynced = [[NSMutableDictionary alloc] init]; //Populate dictionary with contact objects. contactsToBeSynced = self.getNonSynchronisedData; 然后,我尝试使用NSJSONSerialization方法转换对象的字典,但是失败并显示错误。 NSError* error; NSString* jsonString; NSData* jsonData = [NSJSONSerialization dataWithJSONObject:contactsToBeSynced options:NSJSONWritingPrettyPrinted error:&error]; jsonString = [[NSString alloc] […]

NSJSONSerialization – 无法将数据转换为string

我遇到了从Met Office Datapoint API读取JSON的NSJSONSerialization问题。 我得到以下错误 Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn't be completed. (Cocoa error 3840.)" (Unable to convert data to string around character 58208. 我已经检查并认为这是根据字符位置的违规行 {"id":"353556","latitude":"57.1893","longitude":"-5.0929","name":"Sóil Chaorainn"} 根据我尝试过的几个validation器,JSON本身似乎是有效的,我也希望它也来自Met Office这样的大型组织。 NSJSONSerialization不应该与'ó'这样的字符一起工作吗? 如果不是我怎么去改变编码types来处理这个? 提前谢谢了