如何在iPhone屏幕上表示Json数据?

问题描述:

{ 
    Flows =  (
     flow456 
    ); 

    flow456 =  (
     format789, 
     format123 
    ); 
    format123 =  { 
     row1 =   { 
      label = Price; 
      textbox =    { 
       height = 111; 
       width = 333; 
      }; 
     }; 
     row2 =   { 
      button = yes; 
     }; 
    }; 
    format123Rows =  (
     row1, 
     row2 
    ); 
    format789 =  { 
     row1 =   { 
      label = Price; 
      textbox =    { 
       height = 111; 
       width = 333; 
      }; 
     }; 
     row2 =   { 
      button = yes; 
     }; 
    }; 
    format789Rows =  (
     row1, 
     row2 
    ); 
} 

上面是我想要在iphone屏幕上显示的json对象。在屏幕上显示数据的最佳布局是哪种?我试过UIView,UIStackView但无法做到。如何在行中显示它? 如图所示Click here to see image如何在iPhone屏幕上表示Json数据?

您需要将您的json对象转换为字符串并显示在UITextview上。如果您从包中读取JSON对象,则可以在下面使用。

**NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"JSON"]; 

    //création d'un string avec le contenu du JSON 
    NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; 
    self.textview.text = myJSON;** 

如果您从webservice获取JSON对象,则可以尝试以下操作。

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:JSONDic 
                options:NSJSONWritingPrettyPrinted 
                error:&error]; 
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
+0

如果您需要截图,您需要解析JSON。请参考:http://stackoverflow.com/questions/39487854/how-to-parse-json-in-objective-c-ios –

+0

正如我在图像中提到的那样,我想代表那个json数据。我需要哪种布局更适合该布局内的json对象? – mad

+0

我相信你想要在标签中显示一些文本..你需要创建带有标签/文本框的布局(或者你想要的),并且你已经解析并将文本分配给相应的标签。 请参考: 1. https://www.raywenderlich.com/5492/working-with-json-in-ios-5 2. https://www.appcoda.com/parse-xml-and-json -web-service/ –