乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      php – Emoji到JSON編碼,發(fā)布到Web服務(wù)器

       印度阿三17 2019-05-30

      請(qǐng)幫我解決發(fā)布JSON解碼的表情符號(hào)的問(wèn)題.
      我有一個(gè)UITextView,這個(gè)文本視圖可能有一個(gè)表情符號(hào)字符.我將數(shù)據(jù)發(fā)布到Web服務(wù)器,UITextView.text顯示為JSON,問(wèn)題是當(dāng)文本有表情符號(hào)時(shí),我無(wú)法獲取數(shù)據(jù).我所做的是:

      $postData = file_get_contents("php://input") to get the data.
      

      然后我用

      $post = json_decode($postData,true);
      

      解碼數(shù)據(jù)并具有關(guān)聯(lián)數(shù)組并將數(shù)據(jù)插入數(shù)據(jù)庫(kù).

      這是我將數(shù)據(jù)插入數(shù)據(jù)庫(kù)時(shí)??的代碼段.

      $postData = file_get_contents("php://input");
      //$postData = '{"body":"characters here ","subject":"subject here","username":"janus","from_id":"185","to_id":"62"}';
          $post = json_decode($postData,true);
              $data=array(
                      'user_id_from'=>mysql_real_escape_string($post['from_id']),
                      'user_id_to'=>mysql_real_escape_string($post['to_id']),
                      'subject'=>mysql_real_escape_string($post['subject']),
                      'message'=>mysql_real_escape_string($post['body']));
      
                      $messages_obj->insert($data);
      

      沒(méi)有找到表情符號(hào)字符,它工作正常.沒(méi)問(wèn)題.問(wèn)題是當(dāng)找到表情符號(hào)字符時(shí),$post(解碼數(shù)據(jù))中的數(shù)據(jù)為空.

      我試圖使用虛擬數(shù)據(jù)(代碼片段中的第2行)

      //$postData = '{"body":"characters here ","subject":"subject here","username":"janus","from_id":"185","to_id":"62"}';
      

      我成功地將表情符號(hào)字符插入數(shù)據(jù)庫(kù)中.我不知道為什么但是當(dāng)數(shù)據(jù)來(lái)自設(shè)備時(shí)它不同工作($postData = file_get_contents(“php:// input”))

      這就是我在客戶端編碼和發(fā)布數(shù)據(jù)的方式.

          NSMutableDictionary *messageDetails = [[NSMutableDictionary alloc] init];
      [messageDetails setObject:[loginItems objectForKey:@"user_id"] forKey:@"from_id"];
      [messageDetails setObject:recipientID forKey:@"to_id"];
      [messageDetails setObject:@"subject here" forKey:@"subject"];
      [messageDetails setObject:newMessageField.text forKey:@"body"];
          [messageDetails setObject:[loginItems objectForKey:@"username"] forKey:@"username"];
      
      
      NSString *strPostData = [messageDetails JSONRepresentation];
      [messageDetails release];
      
      NSData *postData = [NSData dataWithBytes:[strPostData   UTF8String] length:[strPostData  length]];
      [urlRequest setHTTPMethod:@"POST"];
      [urlRequest setHTTPBody:postData];
      

      BTW,誰(shuí)制作了這些表情符號(hào)字符?他毀了我的命!

      解決方法:

      一旦將數(shù)據(jù)發(fā)送到您的php腳本,您需要將其轉(zhuǎn)換為多字節(jié)字符串:

      $content = mb_convert_encoding($content, 'UTF-8');
      

      你可以使用這個(gè)功能:

      function cb($content){
      
        if(!mb_check_encoding($content, 'UTF-8')
         OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {
      
          $content = mb_convert_encoding($content, 'UTF-8');
      
        }
        return $content;
      }
      

      編輯:數(shù)據(jù)可能是我們的類型application / x-www-form-urlencoded并且該函數(shù)正確轉(zhuǎn)換了它.

      來(lái)源:http://www./content-1-218501.html

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多