我遇到了讓我的UIImage從我收到的JSon工作的問題。 下面就讓我們一起來看看我的JSON讓UIImage從JSON工作
[
{
node_title: "Fumi",
node_uid: "11",
users_node_name: "pae",
nid: "7",
Body: "<p>This is Fumi Restaurant</p> ",
Enterprise Address: "99/9",
Enterprise Email: "[email protected]",
Enterprise Tel: "08111111",
Enterprise Logo: "<img typeof="foaf:Image" src="http://localhost/drupal/sites/default/files/Fumi.jpg" width="300" height="300" alt="" />"
},
{
node_title: "Fuji",
node_uid: "8",
users_node_name: "testent",
nid: "1",
Body: "<p>Fuji</p> ",
Enterprise Address: "Somwhere it belong",
Enterprise Email: "[email protected]",
Enterprise Tel: "02-999-9999",
Enterprise Logo: "<img typeof="foaf:Image" src="http://localhost/drupal/sites/default/files/Fuji.png" width="320" height="320" alt="" />"
}
]
這裏是我的代碼:我能夠獲得所有的JSON我收到了,並告訴他們在這個視圖控制器。但是,由於JSON的內容,[self.detail valueForKey:@「Enterprise Logo」]似乎不起作用。
順便說一句,self.detail是Json對象,我通過做preparetosegue從前一個UITableViewController傳遞。
- (void)viewDidLoad
{
[super viewDidLoad];
self.EnterPriseName.text = [self.detail valueForKey:@"node_title"];
self.EnterPriseTel.text = [self.detail valueForKey:@"users_node_name"];
self.EnterPriseBody.text = [self.detail valueForKey:@"Body"];
self.EnterPriseEmail.text = [self.detail valueForKey:@"nid"];
[self.picLogo setImageWithURL:[NSURL URLWithString:[self.detail valueForKey:@"Enterprise Logo"]]];
}
我也嘗試這種方法工作得很好,但Enterprise Logo中的內容只能包含該img的URL。我試圖儘可能動態地做事情,所以我不期待靜態的答案。有沒有辦法解決這個問題?
[self.picLogo setImageWithURL:[NSURL URLWithString:@"http://localhost/drupal/sites/default/files/Fumi.jpg"]];
這是不合法的JSON。它不會解析。 –
@HotLicks我如何使它合法呢? – user3027109
讓另一端生成合法的JSON。 –