简体   繁体   English

如何在iOS中将JSON对象转换为字符串格式

[英]how to convert json object to string format in ios

This is my json format printed in output log my 1st doubt is how i create separate class for mystatus object in json object and with mystatus object i need to check whether the entered username and password is correct or not, if valid username means it should return value as " s " 这是我在输出日志中打印的json格式,我的第一个疑问是我如何在json对象中为mystatus对象创建单独的类,并使用mystatus对象,我需要检查输入的用户名和密码是否正确,如果有效的用户名意味着应该返回值为s

This my response 这是我的回应

{"login_response":[{"phone":"000000000","status":"Login Successfull",","**mystatus**":"S","mpin":"",","card_store_flag":"0"}]}

please try this..... 请尝试这个.....

NSData *MyData = [jsonResponce dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSString *strString = [NSJSONSerialization JSONObjectWithData:MyData options:NSJSONReadingMutableContainers error:&error];
NSURL *myURL = [[NSURL alloc]initWithString:@"http://yourwebservice link with json"];
NSData *myData = [[NSData alloc]initWithContentsOfURL:myURL];
if (myData == nil)
{
    NSLog(@"NO INTERNET");
}
else
{
    NSLog(@"INTERNET EXIST");
    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:myData options:kNilOptions error:nil];
    for (id element in jsonArray)
    {
        NSString *durum = [element objectForKey:@"yourJsonHeader"];
        if([yourJsonHeader isEqualToString:@"1"])
        {


        }

    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM