小编cra*_*gen的帖子

如何检查如果我从json得到null?

我来自JSON

[{ "照片":空}]

我使用这段代码

NSMutableArray *jPhoto = [NSMutableArray arrayWithArray:(NSArray *)[jsonDict valueForKey:@"photo"]];
Run Code Online (Sandbox Code Playgroud)

如果我想使用if(),我怎么检查它?

编辑

这是JSON数据

   [{"photo":
              [{"image":"http:\/\/www.yohyeh.com\/upload\/shisetsu\/13157\/photo\/1304928459.jpg","title":"test picture","content":"this is description for test picture.\r\n\u8aac\u660e\u6587\u306a\u306e\u306b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb"}
              ,{"image":"http:\/\/www.yohyeh.com\/upload\/shisetsu\/13157\/photo\/1304928115.jpg","title":"nothing","content":"iMirai"}
              ,{"image":"http:\/\/www.yohyeh.com\/upload\/shisetsu\/13157\/photo\/1303276769.jpg","title":"iMirai","content":"Staff"}]}
  ]
Run Code Online (Sandbox Code Playgroud)

这是我的JSON解析器

NSError *theError = nil;     
    NSString *URL = [NSString stringWithFormat:@"http://www.yohyeh.com/apps/get_sub_detail.php?id=%@&menu=photo",g_id];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]];
    NSURLResponse *theResponse =[[[NSURLResponse alloc]init] autorelease];
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];   
    NSMutableString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    NSDictionary *jsonDict = [string JSONValue];
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

iphone json objective-c nsmutablearray ios

12
推荐指数
3
解决办法
2万
查看次数

如何在iTunes中设置来自歌曲的声音本地通知?

我尝试创建闹钟应用程序,但我不知道如何将iTunes中的歌曲设置为本地通知的声音.

现在我使用此代码来调用iTunes

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

        picker.delegate = self;
        picker.allowsPickingMultipleItems = NO;
        picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");

        //[self presentModalViewController: picker animated: YES];
        [self.navigationController pushViewController:picker animated:YES];

        NSLog(@"gsudifghukdsf");
        [picker release];

    }
}

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection 
{
    [self.navigationController popToRootViewControllerAnimated:YES];
    //[self dismissModalViewControllerAnimated: YES];
    NSLog(@"%@",mediaItemCollection);

    UILocalNotification *local = [[UILocalNotification alloc] init]; …
Run Code Online (Sandbox Code Playgroud)

itunes objective-c ipad ios uilocalnotification

7
推荐指数
1
解决办法
2580
查看次数

resignFirstResponder不工作?

我试图在iPad上隐藏键盘,但我不知道为什么resignFirstResponder不起作用.但popToRoot运作良好.

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
    NSString *desc = [NSString stringWithFormat:@"%@",[descTF text]];
    [textField resignFirstResponder];
    [self.navigationController popToRootViewControllerAnimated:YES];


    return YES;
}
Run Code Online (Sandbox Code Playgroud)

那么你能指导我该怎么办?

objective-c ipad ios resignfirstresponder

5
推荐指数
2
解决办法
3863
查看次数

为什么在PDO中使用bindParam但不使用array()?

我有2个问题

我经常看到这个

    $sql->bindParam(':xxx', $yyy, PDO::PARAM_zzz);
    $sql->execute();
Run Code Online (Sandbox Code Playgroud)

为什么不使用(1)

$sql->execute(array(':xxx'=>$yyy));
Run Code Online (Sandbox Code Playgroud)

如果有太多的价值我应该使用(2)

    $sql->bindParam(':aaa', $bbb, PDO::PARAM_zzz);
    $sql->bindParam(':ccc', $ddd, PDO::PARAM_zzz);
    $sql->bindParam(':eee', $fff, PDO::PARAM_zzz);
    $sql->execute();
Run Code Online (Sandbox Code Playgroud)

要么

    $sql->execute(array(':aaa'=>$bbb,':ccc'=>$ddd,':eee'=>$fff));
Run Code Online (Sandbox Code Playgroud)

php mysql pdo

2
推荐指数
1
解决办法
284
查看次数

获取JSON字典中的所有值,而无需通过键访问

JSON示例:

[{ "title1":"Hey", "title2":"Hoh", "title3":"Hah", "title4":"Hoo" }]

如何在(hey,hoh,hah,hoo)不使用的情况下获得价值valueForKey

有人可以指导我吗?

- - - - - - - 编辑 - - - - - - -

我使用JSON-Framework.现在我使用NSDictionary*jsonDict = [string JSONValue];

json dictionary objective-c ios

1
推荐指数
1
解决办法
4248
查看次数

如何将值从javascript传递给html?

我有javascript函数从另一个PHP文件获取JSON但我无法将值传递给html文件.我该怎么做 ??

请稍等一下

<body>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript">
    $.getJSON("getquestion.php",function(result)
    {
        document.getElementById("question").innerHTML = result.test_question;   
        testform.textquestion.value = result.test_question;

    });
    </script>
<form name="testform"> 
<div id="question"></div>
<input id="aaa" type="text" name="textquestion"></input>

</body>
Run Code Online (Sandbox Code Playgroud)

div:问题可以显示来自result.test_question的数据但输入:aaa不能.

能告诉我怎样才能将价值传递给或?我可以指定函数名称.getJSON以及如何?

html javascript jquery

0
推荐指数
1
解决办法
2340
查看次数