• 大小: 11.58MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-26
  • 语言: C/C++
  • 标签: json解析  base64  c++  

资源简介

在前人的基础上增加了json解析封装得到base64或反转成文件。包括案例,源代码。 调用简单,不错的学习案例。 std::unique_ptrp(new const char*(readfile64("{\"filename\":\"D:\\\\job\\\\greatwall\\\\test\\\\1.jpg\"}"))); if (!*p.get()) return -1; int len = strlen(*p.get()); printf("%s\n",*p.get()); char* pcOut = new char[len + MAX_PATH]; memset(pcOut,0x00,sizeof(pcOut)); sprintf(pcOut,"{\"base64\":\"%s\",\"filename\":\"%s\"}",*p.get(),"D:\\\\job\\\\greatwall\\\\test\\\\out.jpg"); //const char* ret = _64tofile(pcOut); std::unique_ptrret(new const char*(_64tofile(pcOut))); printf("%s\n",*ret.get());

资源截图

代码片段和文件信息

/*
  Copyright (c) 2005-2009 by Jakob Schroeter 
  This file is part of the gloox library. http://camaya.net/gloox

  This software is distributed under a license. The full license
  agreement can be found in the file LICENSE in this distribution.
  This software may not be copied modified sold or distributed
  other than expressed in the named license agreement.

  This software is distributed without any warranty.
*/
#include “stdafx.h“
#include “base64.h“

namespace gloox
{

  namespace base64
  {

    static const std::string alphabet64( “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/“ );
    static const char pad = ‘=‘;
    static const char np  = (char)std::string::npos;
    static char table64vals[] =
    {
      62 np np np 63 52 53 54 55 56 57 58 59 60 61 np np np np np
      np np  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17
      18 19 20 21 22 23 24 25 np np np np np np 26 27 28 29 30 31
      32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    };

    inline char table64( unsigned char c )
    {
      return ( c < 43 || c > 122 ) ? np : table64vals[c-43];
    }

    const std::string encode64( const std::string& input )
    {
      std::string encoded;
      char c;
      const std::string::size_type length = input.length();

      encoded.reserve( length * 2 );

      for( std::string::size_type i = 0; i < length; ++i )
      {
        c = static_cast( ( input[i] >> 2 ) & 0x3f );
        encoded += alphabet64[c];

        c = static_cast( ( input[i] << 4 ) & 0x3f );
        if( ++i < length )
          c = static_cast( c | static_cast( ( input[i] >> 4 ) & 0x0f ) );
        encoded += alphabet64[c];

        if( i < length )
        {
          c = static_cast( ( input[i] << 2 ) & 0x3c );
          if( ++i < length )
            c = static_cast( c | static_cast( ( input[i] >> 6 ) & 0x03 ) );
          encoded += alphabet64[c];
        }
        else
        {
          ++i;
          encoded += pad;
        }

        if( i < length )
        {
          c = static_cast( input[i] & 0x3f );
          encoded += alphabet64[c];
        }
        else
        {
          encoded += pad;
        }
      }

      return encoded;
    }

    const std::string decode64( const std::string& input )
    {
      char c d;
      const std::string::size_type length = input.length();
      std::string decoded;

      decoded.reserve( length );

      for( std::string::size_type i = 0; i < length; ++i )
      {
        c = table64(input[i]);
        ++i;
        d = table64(input[i]);
        c = static_cast( ( c << 2 ) | ( ( d >> 4 ) & 0x3 ) );
        decoded += c;
        if( ++i < length )
        {
          c = input[i];
          if( pad == c )
            break;

          c = table64(input[i]);
          d = static_cast( ( ( d << 4 ) & 0xf0 ) | ( ( 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3335  2018-04-11 10:53  base64_file\base64_file\base64.cpp

     文件       1194  2014-03-26 11:27  base64_file\base64_file\base64.h

     文件       4481  2018-04-11 11:40  base64_file\base64_file\base64_file.cpp

     文件        130  2018-04-11 11:35  base64_file\base64_file\base64_file.h

     文件       2644  2018-04-11 09:39  base64_file\base64_file\base64_file.rc

     文件       4801  2018-04-11 10:50  base64_file\base64_file\base64_file.vcxproj

     文件       2078  2018-04-11 10:50  base64_file\base64_file\base64_file.vcxproj.filters

     文件        143  2018-04-11 09:39  base64_file\base64_file\base64_file.vcxproj.user

     文件      27790  2018-03-21 15:56  base64_file\base64_file\cJSON.c

     文件       7526  2015-02-13 18:53  base64_file\base64_file\cJSON.h

     文件       1441  2009-10-13 00:24  base64_file\base64_file\macros.h

     文件       2070  2018-04-11 09:39  base64_file\base64_file\ReadMe.txt

     文件        394  2018-04-11 09:39  base64_file\base64_file\Resource.h

     文件        216  2018-04-11 09:39  base64_file\base64_file\stdafx.cpp

     文件        818  2018-04-11 09:39  base64_file\base64_file\stdafx.h

     文件        236  2018-04-11 09:39  base64_file\base64_file\targetver.h

     文件   57692160  2018-04-11 12:04  base64_file\base64_file.sdf

     文件        900  2018-04-11 09:39  base64_file\base64_file.sln

    ..A..H.     16896  2018-04-11 12:04  base64_file\base64_file.suo

     目录          0  2018-04-11 09:40  base64_file\ipch\base64_file-53c058d8

     目录          0  2018-04-11 12:04  base64_file\base64_file

     目录          0  2018-04-11 09:40  base64_file\ipch

     目录          0  2018-04-11 12:04  base64_file

----------- ---------  ---------- -----  ----

             57769253                    23


评论

共有 条评论