C++以http接口推送json流和图片流

2023-05-16

一、C++推送json流

C++代码:

//
// a single-threaded, multi client(using select), debug webserver - streaming out mjpg.
//  on win, _WIN32 has to be defined, must link against ws2_32.lib (socks on linux are for free)
//

//
// socket related abstractions:
//
#ifdef _WIN32  
    #include <winsock.h>
    #include <windows.h>
    #include <time.h>
    #define PORT        unsigned long
    #define ADDRPOINTER   int*
    struct _INIT_W32DATA
    {
       WSADATA w;
       _INIT_W32DATA() { WSAStartup( MAKEWORD( 2, 1 ), &w ); }
    } _init_once;
#else       /* ! win32 */
    #include <unistd.h>
    #include <sys/time.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #define PORT        unsigned short
    #define SOCKET    int
    #define HOSTENT  struct hostent
    #define SOCKADDR    struct sockaddr
    #define SOCKADDR_IN  struct sockaddr_in
    #define ADDRPOINTER  unsigned int*
    #define INVALID_SOCKET -1
    #define SOCKET_ERROR   -1
#endif /* _WIN32 */


#include<signal.h>

#include <iostream>
using std::cerr;
using std::endl;

#include "opencv2/opencv.hpp"
using namespace cv;

static int close_socket(SOCKET s) {
    std::cout << "close_socket function "<< endl;
    int close_output = ::shutdown(s, 1); // 0 close input, 1 close output, 2 close both
    char *buf = (char *)calloc(1024, sizeof(char));
    ::recv(s, buf, 1024, 0);
    free(buf);
    int close_input = ::shutdown(s, 0);
    int result = close(s);
    std::cerr << "Close socket: out = " << close_output << ", in = " << close_input << " \n";
    return result;
}


//struct mat_cv : cv::Mat { int a[0]; };

// void send_mjpeg(mat_cv* mat, int port, int timeout, int quality)
// {
//     try {
//         std::lock_guard<std::mutex> lock(mtx_mjpeg);
//         static MJPG_sender wri(port, timeout, quality);
//         //cv::Mat mat = cv::cvarrToMat(ipl);
//         wri.write(*(cv::Mat*)mat);
//         std::cout << " MJPEG-stream sent. \n";
//     }
//     catch (...) {
//         cerr << " Error in send_mjpeg() function \n";
//     }
// }


// =====================================================================================================================================================
class JSON_sender
{
    SOCKET sock;
    SOCKET maxfd;
    fd_set master;
    int timeout; // master sock timeout, shutdown after timeout usec.
    int close_all_sockets;

    int _write(int sock, char const*const s, int len)
    {
        if (len < 1) { len = strlen(s); }
        return ::send(sock, s, len, 0);
    }

public:

    JSON_sender(int port = 0, int _timeout = 400000)
        : sock(INVALID_SOCKET)
        , timeout(_timeout)
    {
        close_all_sockets = 0;
        FD_ZERO(&master);
        if (port)
            open(port);
    }

    ~JSON_sender()
    {
        std::cout << "exit JSON_sender "<< std::endl;
        close_all();
        release();
    }

    bool release()
    {
        if (sock != INVALID_SOCKET)
            ::shutdown(sock, 2);
        sock = (INVALID_SOCKET);
        return false;
    }

    void close_all()
    {
        close_all_sockets = 1;
        write("\n]");   // close JSON array
    }

    bool open(int port)
    {
        sock = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

        SOCKADDR_IN address;
        address.sin_addr.s_addr = INADDR_ANY;
        address.sin_family = AF_INET;
        address.sin_port = htons(port);    // ::htons(port);
        int reuse = 1;
        if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) < 0)
            cerr << "setsockopt(SO_REUSEADDR) failed" << endl;

        // Non-blocking sockets
        // Windows: ioctlsocket() and FIONBIO
        // Linux: fcntl() and O_NONBLOCK
#ifdef WIN32
        unsigned long i_mode = 1;
        int result = ioctlsocket(sock, FIONBIO, &i_mode);
        if (result != NO_ERROR) {
            std::cerr << "ioctlsocket(FIONBIO) failed with error: " << result << std::endl;
            signal(SIGPIPE, SIG_IGN);
        }
#else // WIN32
        ;
        // int flags = fcntl(sock, F_GETFL, 0);
        // fcntl(sock, F_SETFL, flags | O_NONBLOCK);
#endif // WIN32

#ifdef SO_REUSEPORT
        if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)) < 0){
            //signal(SIGPIPE, SIG_IGN);
            cerr << "setsockopt(SO_REUSEPORT) failed" << endl;
        }
#endif
        if (::bind(sock, (SOCKADDR*)&address, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
        {
            cerr << "error JSON_sender: couldn't bind sock " << sock << " to port " << port << "!" << endl;
            //signal(SIGPIPE, SIG_IGN);
            return release();
        }
        if (::listen(sock, 10) == SOCKET_ERROR)
        {
            cerr << "error JSON_sender: couldn't listen on sock " << sock << " on port " << port << " !" << endl;
            //signal(SIGPIPE, SIG_IGN);
            return release();
        }
        FD_ZERO(&master);
        FD_SET(sock, &master);
        maxfd = sock;
        return true;
    }

    bool isOpened()
    {
        return sock != INVALID_SOCKET;
    }

    bool write(char const* outputbuf)
    {
        fd_set rread = master;
        struct timeval select_timeout = { 0, 0 };
        struct timeval socket_timeout = { 0, timeout };
        if (::select(maxfd + 1, &rread, NULL, NULL, &select_timeout) <= 0){
            signal(SIGPIPE, SIG_IGN);
            return true; // nothing broken, there's just noone listening
        }
        
        int outlen = static_cast<int>(strlen(outputbuf));

#ifdef _WIN32
        for (unsigned i = 0; i<rread.fd_count; i++)
        {
            int addrlen = sizeof(SOCKADDR);
            SOCKET s = rread.fd_array[i];    // fd_set on win is an array, while ...
#else
        for (int s = 0; s <= maxfd; s++)
        {
            socklen_t addrlen = sizeof(SOCKADDR);
            if (!FD_ISSET(s, &rread))      // ... on linux it's a bitmask ;)
                continue;
#endif
            if (s == sock) // request on master socket, accept and send main header.
            {
                SOCKADDR_IN address = { 0 };
                SOCKET      client = ::accept(sock, (SOCKADDR*)&address, &addrlen);
                if (client == SOCKET_ERROR)
                {
                    cerr << "error JSON_sender: couldn't accept connection on sock " << sock << " !" << endl;
                    //signal(SIGPIPE, SIG_IGN);
                    return false;
                }
                if (setsockopt(client, SOL_SOCKET, SO_RCVTIMEO, (char *)&socket_timeout, sizeof(socket_timeout)) < 0) {
                    //signal(SIGPIPE, SIG_IGN);
                    cerr << "error JSON_sender: SO_RCVTIMEO setsockopt failed\n";
                }
                if (setsockopt(client, SOL_SOCKET, SO_SNDTIMEO, (char *)&socket_timeout, sizeof(socket_timeout)) < 0) {
                    //signal(SIGPIPE, SIG_IGN);
                    cerr << "error JSON_sender: SO_SNDTIMEO setsockopt failed\n";
                }
                maxfd = (maxfd>client ? maxfd : client);
                FD_SET(client, &master);
                _write(client, "HTTP/1.0 200 OK\r\n", 0);
                _write(client,
                    "Server: Mozarella/2.2\r\n"
                    "Accept-Range: bytes\r\n"
                    "Connection: close\r\n"
                    "Max-Age: 0\r\n"
                    "Expires: 0\r\n"
                    "Cache-Control: no-cache, private\r\n"
                    "Pragma: no-cache\r\n"
                    "Content-Type: application/json\r\n"
                    //"Content-Type: multipart/x-mixed-replace; boundary=boundary\r\n"
                    "\r\n", 0);
                _write(client, "[\n", 0);   // open JSON array
                int n = _write(client, outputbuf, outlen);
                cerr << "JSON_sender: new client " << client << endl;
            }
            else // existing client, just stream pix
            {
                //char head[400];
                // application/x-resource+json or application/x-collection+json -  when you are representing REST resources and collections
                // application/json or text/json or text/javascript or text/plain.
                // https://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type
                //sprintf(head, "\r\nContent-Length: %zu\r\n\r\n", outlen);
                //sprintf(head, "--boundary\r\nContent-Type: application/json\r\nContent-Length: %zu\r\n\r\n", outlen);
                //_write(s, head, 0);
                if (!close_all_sockets) _write(s, ", \n", 0);
                int n = _write(s, outputbuf, outlen);
                if (n < (int)outlen)
                {
                    cerr << "JSON_sender: kill client " << s << endl;
                    //signal(SIGPIPE, SIG_IGN);
                    //close_socket(s);
                    //::shutdown(s, 2);
                    FD_CLR(s, &master);
                }

                if (close_all_sockets) {
                    int result = close_socket(s);
                    cerr << "JSON_sender: close clinet: " << result << " \n";
                    //signal(SIGPIPE, SIG_IGN);
                    continue;
                }
            }
        }
        if (close_all_sockets) {
            int result = close_socket(sock);
            cerr << "JSON_sender: close acceptor: " << result << " \n\n";
        }
        return true;
        }
};
// ----------------------------------------


int main()
{
    static std::unique_ptr<JSON_sender> js_ptr;
    //static std::mutex mtx;


    while(1)
    {
        try{
            if(!js_ptr) js_ptr.reset(new JSON_sender(22221, 400000));
            
            js_ptr->write("hello world");
            std::cout << " JSON-stream sent. \n";
        }catch (...) {
            std::cout << " Error in send_json() function \n";
        }   
        

    }
    std::cout << "finish" << std::endl;
    return 0;
}

打开浏览器,输入ip地址:22221,就可以看到推送的json流了

二、C++推送图片流

C++代码:

//
// a single-threaded, multi client(using select), debug webserver - streaming out mjpg.
//  on win, _WIN32 has to be defined, must link against ws2_32.lib (socks on linux are for free)
//

//
// socket related abstractions:
//
#ifdef _WIN32  
    #include <winsock.h>
    #include <windows.h>
    #include <time.h>
    #define PORT        unsigned long
    #define ADDRPOINTER   int*
    struct _INIT_W32DATA
    {
       WSADATA w;
       _INIT_W32DATA() { WSAStartup( MAKEWORD( 2, 1 ), &w ); }
    } _init_once;
#else       /* ! win32 */
    #include <unistd.h>
    #include <sys/time.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #define PORT        unsigned short
    #define SOCKET    int
    #define HOSTENT  struct hostent
    #define SOCKADDR    struct sockaddr
    #define SOCKADDR_IN  struct sockaddr_in
    #define ADDRPOINTER  unsigned int*
    #define INVALID_SOCKET -1
    #define SOCKET_ERROR   -1
#endif /* _WIN32 */


#include<signal.h>

#include <iostream>
using std::cerr;
using std::endl;

#include "opencv2/opencv.hpp"
using namespace cv;

// static int close_socket(SOCKET s) {
    // int close_output = ::shutdown(s, 1); // 0 close input, 1 close output, 2 close both
    // char *buf = (char *)calloc(1024, sizeof(char));
    // ::recv(s, buf, 1024, 0);
    // free(buf);
    // int close_input = ::shutdown(s, 0);
    // int result = close(s);
    // std::cerr << "Close socket: out = " << close_output << ", in = " << close_input << " \n";
    // return result;
// }


class MJPG_sender
{
    SOCKET sock;
    SOCKET maxfd;
    fd_set master;
    int timeout; // master sock timeout, shutdown after timeout usec.
    int quality; // jpeg compression [1..100]
    int close_all_sockets;

    int _write(int sock, char const*const s, int len)
    {
        if (len < 1) { len = strlen(s); }
        return ::send(sock, s, len, 0);
    }

public:

    MJPG_sender(int port = 0, int _timeout = 400000, int _quality = 30)
        : sock(INVALID_SOCKET)
        , timeout(_timeout)
        , quality(_quality)
    {
        close_all_sockets = 0;
        FD_ZERO(&master);
        if (port)
            open(port);
    }

    ~MJPG_sender()
    {
        //close_all();
        release();
    }

    bool release()
    {
        if (sock != INVALID_SOCKET)
            ::shutdown(sock, 2);
        sock = (INVALID_SOCKET);
        return false;
    }

    void close_all()
    {
        close_all_sockets = 1;
        cv::Mat tmp(cv::Size(10, 10), CV_8UC3);
        write(tmp);
    }

    bool open(int port)
    {
        sock = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

        SOCKADDR_IN address;
        address.sin_addr.s_addr = INADDR_ANY;
        address.sin_family = AF_INET;
        address.sin_port = htons(port);    // ::htons(port);
        int reuse = 1;
        if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) < 0)
            cerr << "setsockopt(SO_REUSEADDR) failed" << endl;
            signal(SIGPIPE, SIG_IGN);

        // Non-blocking sockets
        // Windows: ioctlsocket() and FIONBIO
        // Linux: fcntl() and O_NONBLOCK
#ifdef WIN32
        unsigned long i_mode = 1;
        int result = ioctlsocket(sock, FIONBIO, &i_mode);
        if (result != NO_ERROR) {
            std::cerr << "ioctlsocket(FIONBIO) failed with error: " << result << std::endl;
            signal(SIGPIPE, SIG_IGN);
        }
#else // WIN32
        ;
        // int flags = fcntl(sock, F_GETFL, 0);
        // fcntl(sock, F_SETFL, flags | O_NONBLOCK);
#endif // WIN32

#ifdef SO_REUSEPORT
        if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)) < 0)
            cerr << "setsockopt(SO_REUSEPORT) failed" << endl;
            signal(SIGPIPE, SIG_IGN);
#endif
        if (::bind(sock, (SOCKADDR*)&address, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
        {
            cerr << "error MJPG_sender: couldn't bind sock " << sock << " to port " << port << "!" << endl;
            signal(SIGPIPE, SIG_IGN);
            return release();
        }
        if (::listen(sock, 10) == SOCKET_ERROR)
        {
            cerr << "error MJPG_sender: couldn't listen on sock " << sock << " on port " << port << " !" << endl;
            signal(SIGPIPE, SIG_IGN);
            return release();
        }
        FD_ZERO(&master);
        FD_SET(sock, &master);
        maxfd = sock;
        return true;
    }

    bool isOpened()
    {
        return sock != INVALID_SOCKET;
    }

    bool write(const Mat & frame)
    {
        fd_set rread = master;
        struct timeval select_timeout = { 0, 0 };
        struct timeval socket_timeout = { 0, timeout };
        struct timeval to = {0,timeout};
        //SOCKET maxfd = sock+1;
        if (::select(maxfd+1, &rread, NULL, NULL, &to) <= 0){
            std::cout << "111111111111"<<std::endl;
            signal(SIGPIPE, SIG_IGN);
            return true; // nothing broken, there's just noone listening
        }
            


        std::vector<uchar> outbuf;
        std::vector<int> params;
        params.push_back(IMWRITE_JPEG_QUALITY);
        params.push_back(quality);
        cv::imencode(".jpg", frame, outbuf, params);  //REMOVED FOR COMPATIBILITY
        // https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#ga292d81be8d76901bff7988d18d2b42ac
        //std::cerr << "cv::imencode call disabled!" << std::endl;
        int outlen = static_cast<int>(outbuf.size());

#ifdef _WIN32
        for (unsigned i = 0; i<rread.fd_count; i++)
        {
            //int addrlen = sizeof(SOCKADDR);
            SOCKET s = rread.fd_array[i];    // fd_set on win is an array, while ...
#else
        for (int s = 0; s <= maxfd+10; s++)
        //for(int s= 0;s<10000;s++)
        {
            socklen_t addrlen = sizeof(SOCKADDR);
            if (!FD_ISSET(s, &rread))      // ... on linux it's a bitmask ;)
                continue;
#endif
            if (s == sock) // request on master socket, accept and send main header.
            {
                std::cout << "2222222222222"<<std::endl;
                SOCKADDR_IN address = { 0 };
                SOCKET      client = ::accept(sock, (SOCKADDR*)&address, &addrlen);
                if (client == SOCKET_ERROR)
                {
                    cerr << "error MJPG_sender: couldn't accept connection on sock " << sock << " !" << endl;
                    signal(SIGPIPE, SIG_IGN);
                    return false;
                }
                // if (setsockopt(client, SOL_SOCKET, SO_RCVTIMEO, (char *)&socket_timeout, sizeof(socket_timeout)) < 0) {
                    // cerr << "error MJPG_sender: SO_RCVTIMEO setsockopt failed\n";
                // }
                // if (setsockopt(client, SOL_SOCKET, SO_SNDTIMEO, (char *)&socket_timeout, sizeof(socket_timeout)) < 0) {
                    // cerr << "error MJPG_sender: SO_SNDTIMEO setsockopt failed\n";
                // }
                maxfd = (maxfd>client ? maxfd : client);
                FD_SET(client, &master);
                _write(client, "HTTP/1.0 200 OK\r\n", 0);
                _write(client,
                    "Server: Mozarella/2.2\r\n"
                    "Accept-Range: bytes\r\n"
                    "Connection: close\r\n"
                    "Max-Age: 0\r\n"
                    "Expires: 0\r\n"
                    "Cache-Control: no-cache, private\r\n"
                    "Pragma: no-cache\r\n"
                    "Content-Type: multipart/x-mixed-replace; boundary=mjpegstream\r\n"
                    "\r\n", 0);
                cerr << "MJPG_sender: new client " << client << endl;
            }
            else // existing client, just stream pix
            {
                std::cout << "333333333333333333"<<std::endl;
                // if (close_all_sockets) {
                    // int result = close_socket(s);
                    // cerr << "MJPG_sender: close clinet: " << result << " \n";
                    // continue;
                // }

                char head[400];
                sprintf(head, "--mjpegstream\r\nContent-Type: image/jpeg\r\nContent-Length: %zu\r\n\r\n", outlen);
                _write(s, head, 0);
                int n = _write(s, (char*)(&outbuf[0]), outlen);
                cerr << "known client: " << s << ", sent = " << n << ", must be sent outlen = " << outlen << endl;
                if (n < (int)outlen)
                {
                    cerr << "MJPG_sender: kill client " << s << endl;
                    signal(SIGPIPE, SIG_IGN);
                    //::shutdown(s, 2);
                    //close_socket(s);
                    FD_CLR(s, &master);
                }
            }
        }
        // if (close_all_sockets) {
            // int result = close_socket(sock);
            // cerr << "MJPG_sender: close acceptor: " << result << " \n\n";
        // }
        return true;
    }
};
// ----------------------------------------



//struct mat_cv : cv::Mat { int a[0]; };

// void send_mjpeg(mat_cv* mat, int port, int timeout, int quality)
// {
//     try {
//         std::lock_guard<std::mutex> lock(mtx_mjpeg);
//         static MJPG_sender wri(port, timeout, quality);
//         //cv::Mat mat = cv::cvarrToMat(ipl);
//         wri.write(*(cv::Mat*)mat);
//         std::cout << " MJPEG-stream sent. \n";
//     }
//     catch (...) {
//         cerr << " Error in send_mjpeg() function \n";
//     }
// }


int main()
{
    //static std::mutex mtx_mjpeg;
    VideoCapture cap;
    bool ok = cap.open("rtsp://admin:123456@192.168.10.11:554/h264/ch01/main/av_stream");
    if ( ! ok ) 
    {
        printf("no cam found ;(.\n");
        return 1;
    }

    //MJPGWriter wri(22222); // http://your-server:7777
    
    //while( cap.isOpened() && wri.isOpened() )
    while(1)
    {
        try{
            
            Mat frame;
            cap >> frame;

            // wri.write(frame);
            // printf("ok");
            // //imshow("lalala",frame);
            // int k = waitKey(10); 
            // if ( k==27 )
            //   break;
            
            //std::lock_guard<std::mutex> lock(mtx_mjpeg);
            static MJPG_sender wri(22222, 400000, 30);
            
            //cv::Mat mat = cv::cvarrToMat(ipl);
            //wri.write(*(cv::Mat*)frame);
            try{
                wri.write(frame);
            }catch (...) {
                std::cout << " wri.write error";
            }
            
            std::cout << " MJPEG-stream sent. \n";
            //utime.sleep(1)

        }catch (...) {
            VideoCapture cap;
            bool ok = cap.open("rtsp://admin:123456@192.168.10.11:554/h264/ch01/main/av_stream");

            std::cout << " Error in send_mjpeg() function \n";
        }
            
    }
    return 0;
}

打开浏览器,输入ip地址:22222,就可以看到推送的json流了

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++以http接口推送json流和图片流 的相关文章

  • 使用 REST 协议和 JSON 数据格式测试 Web 服务的最佳工具是什么? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我是使用 JSON 数据格式测试 REST Web 服务的新手 我尝试了SOUPUI 但不幸的是不支持
  • 如何防止 Firefox 缓存

    我尝试了很多可能的解决方案 但无法解决问题 这些不起作用 有人可以帮忙吗 我正在使用jsp servlet application 是websphere Portal 6 1 的一个portlet 切勿
  • 使用 JSONDecoder 解码的对象的打印输出出现问题

    我正在尝试快速解码 JSON 字符串 但在解码后访问属性时遇到一些奇怪的问题 这是我从本地存储的 JSON 文件检索的 JSON 文件的内容 word a usage partOfSpeech determiner 这是访问 JSON 文件
  • 为什么 Twitter API 返回错误的推文 ID?

    我使用 Twitter API 来检索用户主页时间线推文 我使用 json 响应格式 最近推文 ID 在 API 中只是 id 被重新调整错误 举个例子 通常它应该像这样返回 id 14057503720 示例来自twitter控制台 但是
  • 无法验证模式并正确使用additionalProperties

    我正在尝试验证我的 JSON 架构并使用 extraProperties false 来确认没有其他属性 我的responseBody看起来像这样 id 1234567890987654 email email protected cdn
  • 解析包含 json 字符串的 json

    我有一个 json 里面有另一个 json 但它在双引号内 因此它给了我一个解析错误 除了使用之外还有什么方法可以解析这个jsongsub替换双引号 obj Name FirstName Douglas LastName Crockford
  • PostgreSQL 中 JSON 数据类型的大小限制

    有谁知道 PostgreSQL 9 2 中 JSON 数据类型的大小限制是多少 查看 PostgreSQL 9 2 1 的源代码 Source postgresql 9 2 1 src backend utils adt json c In
  • Crystal lang如何从http获取二进制文件

    In Ruby require open uri download open http example com download pdf IO copy stream download my file pdf 如何在水晶中做同样的事情 我们
  • 如何在 G-WAN 中添加 HTTP/2

    我想知道是否可以通过使用解决方案 nghttp2 https nghttp2 org https nghttp2 org 很抱歉这么晚才回答 出于某种原因 Stackoverflow 没有通知我们这个问题 我之所以找到它只是因为收到了更新的
  • AngularJS 1.X 中的异步调用是如何工作的? $Http 调用没有返回值

    我有以下名为的函数getvalue 它与控制器一起位于 AngularJS 模块内 我试图在单击事件上调用此函数 调用控制器中的另一个函数 我希望我很清楚 功能 function getvalue Data http var value u
  • 从 React.js 中的 json 文件获取数据

    我有一个 json 文件调用 data json 例如 我使用 React js id 1 title Child Bride id 2 title Last Time I Committed Suicide The id 3 title
  • 如何解码这个 JSON 字符串?

    这是我从 feed finder url 中得到的字符串 JSON 编码 updated 1265787927 id http www google com reader api 0 feed finder q u003dhttp itca
  • 如何为现代 C++ 迭代 JSON 中的 JSON

    我想迭代 json 对象中的每个条目 但我收到一个又一个难以理解的错误 下面的例子如何改正 include
  • 使用 JSONP 时出现“无效标签”?

    我的 JSONP 请求有问题 数据不会显示 Firebug 显示 无效标签 错误 我的 JavaScript ajax url link dataType jsonp beforeSend function xhr var base64 b
  • android中如何将字符串转换为unicode

    我正在解析一些unicodes from json to my android应用程序 API 给出unicodes像这样的图标 ue600 当我将这个unicode直接添加到textview like textview setText u
  • 数组反序列化的Gson数组

    我有以下 JSON 结构 id 1 subcategories id 2 subcategories id 3 subcategories id 4 subcategories id 5 subcategories 类别的模型类 为简单起见
  • Mongoose查询结果是只读的吗?

    如何修改 Mongoose 查询返回的对象 假设我们有以下模式 var S new mongoose Schema name String field String 我对结果进行了以下查询和修改 var retrieve function
  • 使用 JSONKit 解析 JSON 文件

    我正在构建一个音叉应用程序 货叉应允许最多 12 个预设节距 此外 我希望允许用户选择一个主题 每个主题都会加载一组预设 不必使用所有预设 我的配置文件看起来像这样 theme A3 comment An octave below conc
  • 使用 Ajax Jquery post 请求进行 Json 劫持

    昨天 我读了一些关于如何预防的好文章使用 Asp Net MVC 进行 Json 劫持 http haacked com archive 2009 06 24 json hijacking aspx 规则是 永远不要通过 get 请求发送
  • Java Junit 测试 HTTP POST 请求

    我需要测试以下方法而不改变方法本身 该方法向服务器发出 POST 方法 但我需要制作一个独立于服务器的测试用例 在将其重定向到本地文件之前 我测试了类似的方法 但为此我将协议指定为文件 主机名指定为 localhost 端口指定为 1 我的

随机推荐