ios - JSON解析UITableViewController
<p><p>我正在尝试将我的 JSON 数据传递到 UITableViewController。我确实设法将我的一个 JSON 传递到 UITableView 并在用户执行 egue 时将其显示在下一个 ViewController 上。问题是我得到了 4 个 JSON 数据,我希望它显示在 ViewController 上。由于我的 JSON 格式,我无法执行 ObjectForKey。 </p>
<p>这是我的 JSON </p>
<pre><code>{
uid: "60",
name: "pae1344",
mail: "[email protected]",
theme: "",
signature: "",
signature_format: "plain_text",
created: "1396189622",
access: "0",
login: "1396189622",
status: "1",
timezone: "Asia/Bangkok",
language: "",
picture: "0",
init: "[email protected]",
data: null,
uri: "http://localhost/drupal/rest/user/60"
},
</code></pre>
<p>这是来自 myTableViewController 的代码。</p>
<pre><code>#import "TestinViewController.h"
#import "AFNetworking.h"
#import "TestinCell.h"
#import "EDscriptionViewController.h"
@interface TestinViewController ()
@end
@implementation TestinViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = ;
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
;
self.finishedGooglePlacesArray = [ init];
;
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
;
// Dispose of any resources that can be recreated.
}
-(void)makeRestuarantsRequests
{
NSURL *url = ;
NSURLRequest *request = ;
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject)
{
self.googlePlacesArrayFromAFNetworking = ;
self.body = ;
self.tel = ;
self.mail = ;
;
NSLog(@"%@", self.googlePlacesArrayFromAFNetworking);
NSLog(@"%@" , self.body);
NSLog(@"%@", self.tel);
NSLog(@"%@", self.mail);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject)
{
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
TestinCell *cell = ;
if (cell ==Nil){
cell = [initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.txtEnterPriseName.text = ;
cell.txtEnterPriseBody.text = ;
cell.txtEnterPriseEmail.text = ;
cell.txtEnterPriseTel.text = ;
// Configure the cell...
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath * indexPath = ;
EDscriptionViewController *destViewController = (EDscriptionViewController*) segue.destinationViewController ;
// destViewController.enterprise = ;
destViewController.detail = ;
destViewController.Ebody = ;
destViewController.EEmail = ;
destViewController.ETel = ;
// destViewController.ebody = ;
// destViewController.etel = ;
// destViewController.email = ;
//
}
</code></pre>
<p>有没有办法让我的 JSON 变成字典,所以我可以使用 ObjectForKey 选择要显示的内容? </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>首先通过将 .m 和 .h 文件添加到您的项目来使用此库:</p>
<p> <a href="https://github.com/johnezang/JSONKit" rel="noreferrer noopener nofollow">JSONKit</a> </p>
<p>然后您可以将 JSON 字符串转换为字典。 </p>
<pre><code>//JSONString is a NSString variable with the JSON
NSDictionary *myJSONDic =
NSLog(@"User Id is : %@",);
</code></pre></p>
<p style="font-size: 20px;">关于ios - JSON解析UITableViewController,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22755762/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22755762/
</a>
</p>
页:
[1]