JSON - Php/SQL iPhone APP 问题/帮助
嘿,小组,第一次在这里发帖,
我对 JSON/PHP/mySQL 世界有点陌生,但过去几年一直在围绕 iPhone 设计,尽管这个话题是我刚刚进入的一个新领域。
我已经完成了 JSON iPhone 示例,这些示例允许我创建 UITableView 并将 JSON 数据显示到 TableViewCells (CustomCells) 中,并将数据 (NSDictionary) 显示到 UILabels
我现在遇到的问题是,我想要一个显示此信息的应用程序从 JSON 到常规 UIViewController 而不是 UITableView 上的几个 UILabel
任何帮助将不胜感激,
我使用和学习的 JSON 和 UITABLE 的示例来自 http://tempered.mobi/%20 我在我的应用程序中使用了该示例,但合并了一些其他内容,例如自定义单元格
,但是现在当用户选择特定单元格时,我希望它从另一个 JSON 文件加载特定数据,并且无法将其加载到 UILabel 或 UITextView 中UIViewController
帮助:-)
Hey group, first time posting here
I am somewhat new to the JSON/PHP/mySQL world, but been around iPhone designing for the past few years, though this topic of conversation is a while new area I am entering.
I have done JSON iPhone examples that allow me to create a UITableView and display the JSON data into the TableViewCells (CustomCells) and displays the data (NSDictionary)into UILabels
The problem I am having now, is that I want an APP that displays this information from the JSON into just a couple of UILabel's on a regular UIViewController and not a UITableView
any help would greatly be appreciated,
the example I used and learned for JSON and UITABLE was from http://tempered.mobi/%20
I used that example from my app, but incorporated a few other things like CUSTOM cells
however now when the USER selects the specific CELL I want it to load specific data from another JSON file, and cannot get it to load in a UILabel or UITextView in a UIViewController
HELP :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定我是否完全理解您的查询,当用户单击表格单元格时,您希望应用程序以 JSON 格式请求数据并将其显示在视图上的标签中?正确的?
如果是这样,那么我会修改 didSelectRowAtIndexPath 方法。使用索引确定要触发哪个 JSON 请求,将结果加载到对象/数组/字典中,然后从此数据源设置标签文本。
如果我误解了你的问题,我深表歉意。
Not sure if I completely understand your query, when the user clicks on a table cell you want the app to do a request for data in JSON format and display it in labels on a view? correct?
If so, then I'd modify the didSelectRowAtIndexPath method. Use the index to determine which JSON request to fire, load the results into object/array/dictionary and then set the labels text from this data source.
Apologizes if I mis-understood your question.
这是我的编码,这是选择 TABLEViewCell 后加载的 XIB,我提前对格式表示歉意,我不知道为什么它没有正确显示,因为我只是从 Xcode
.h 文件 复制和粘贴,我添加的只是
}
@property(保留,非原子)NSArray *rows;
(补充说明:我显然将 UILabels 和 UIText View 连接到特定 XIB 中的标签和文本视图)并使用 homeTeam.text = @""; 进行了测试(在实现文件中)确保它们正常运行
.m 文件
import "CJSONDeserializer.h"
import "JSON.h"
@synthesize homeTeam,awayTeam,awayTeam2;
(void)viewDidLoad {
[超级viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://yourserver.com/yourdata.json"]; // 修改它以匹配您的网址。
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; // 拉取 URL
//NSLog(jsonreturn);
// 看控制台就可以看到结果是什么
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *错误 = nil;
// 在“真实”代码中,你应该用 try 和 catch 包围它
NSDictionary * dict = [[CJSONDeserializer反序列化器] deserializeAsDictionary:jsonData错误:&错误];
如果(字典)
{
rows = [dict objectForKey:@"users"];
[行保留];
}
NSLog(@"数组:%@",行); //注意这个 NSLOG 确实打印了从 SQL 数据库抓取的 JSON 数据
awayTeam2.text =[dict objectForKey:@"awayteam"];
awayTeam.text = [dict objectForKey:@"awayteam"];
[jsonreturn 发布];
控制台:如您所见,它很好地获取了我的 JSON 数据......
大批: (
{
awayicon = "布兰普顿.png";
客队=密西沙加;
homeicon = "密西沙加.jpg";
主队=布兰普顿;
hsc最终= 10;
id = 1;
}
)
Here is my coding to it, this is the XIB that is loaded once the TABLEViewCell is selected, i apologize in advanced for the formatting, I dont know why it is not coming out properly as I am simply copying and pasting from Xcode
.h File, all I added was
}
@property (retain, nonatomic) NSArray *rows;
(added note: I obviously hooked up the UILabels and UIText View to my labels and text view in that specific XIB) and have tested using the homeTeam.text = @""; (in the Implementation file)to make sure they are functioning properly
.m file
import "CJSONDeserializer.h"
import "JSON.h"
@synthesize homeTeam, awayTeam, awayTeam2;
(void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://yourserver.com/yourdata.json"]; // Modify this to match your url.
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; // Pulls the URL
//NSLog(jsonreturn);
// Look at the console and you can see what the restults are
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
// In "real" code you should surround this with try and catch
NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
if (dict)
{
rows = [dict objectForKey:@"users"];
[rows retain];
}
NSLog(@"Array: %@",rows); //making NOTE this NSLOG does print my JSON Data grabbed from the SQL Database
awayTeam2.text =[dict objectForKey:@"awayteam"];
awayTeam.text = [dict objectForKey:@"awayteam"];
[jsonreturn release];
CONSOLE: as you can see it grabs my JSON data just fine....
Array: (
{
awayicon = "Brampton.png";
awayteam = Mississauga;
homeicon = "Mississauga.jpg";
hometeam = Brampton;
hscfinal = 10;
id = 1;
}
)