【问题标题】:How to represent Json data on iphone screen?如何在 iPhone 屏幕上表示 Json 数据?
【发布时间】:2017-04-20 04:15:29
【问题描述】:
{
    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

【问题讨论】:

    标签: ios objective-c iphone json


    【解决方案1】:

    您需要将您的 json 对象转换为 String 并显示在 UITextview 上。如果您正在从 bundle 中读取 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];
    

    【讨论】:

    猜你喜欢
    • 2016-04-24
    • 2018-09-18
    • 1970-01-01
    • 2017-11-12
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多