Разбор JSON из HTTParty с использованием Ruby on Rails

Вы можете использовать HTML5 Web Sockets:

var connection = new WebSocket('ws://IPAddress:Port');

connection.onopen = function () {
  connection.send('Ping'); // Send the message 'Ping' to the server
};

http://www.html5rocks.com/en/tutorials/websockets/basics/

Ваш сервер также должен прослушиваться с сервера WebSocket, такого как pywebsocket, иначе вы можете написать свой собственный, как описано в Mozilla

Дополнительно:

Обновить : Из проекта W3C в январе 2016 года:

Это будет возможно через интерфейс навигатора, как показано ниже:

http://raw-sockets.sysapps.org/# interface-tcpsocket

https://www.w3.org/TR/tcp-udp-sockets/

navigator.tcpPermission.requestPermission({remoteAddress:"127.0.0.1", remotePort:6789}).then(
  () => {
    // Permission was granted
    // Create a new TCP client socket and connect to remote host
    var mySocket = new TCPSocket("127.0.0.1", 6789);

    // Send data to server
    mySocket.writeable.write("Hello World").then(
        () => {

            // Data sent sucessfully, wait for response
            console.log("Data has been sent to server");
            mySocket.readable.getReader().read().then(
                ({ value, done }) => {
                    if (!done) {
                        // Response received, log it:
                        console.log("Data received from server:" + value);
                    }

                    // Close the TCP connection
                    mySocket.close();
                }
            );
        },
        e => console.error("Sending error: ", e);
    );

0
задан ray 17 January 2019 в 05:53
поделиться

1 ответ

HTTParty.get возвращает инкапсулированный тип ответа класса HTTParty::Response, вам нужно извлечь parsed response из этого с помощью:

response = HTTParty.get(
  'http://codekyt.in/froodle-wp/wp-json/data/v2/projects?client_key=12345',
  :headers =>{'Content-Type' => 'application/json'}
)
@category = response.parsed_response # this will return the json.

Также вам не нужно повторять @category в В вашем случае объект json является единственным, и вы можете использовать его напрямую:

<%=@category["restaurant_name"]%>
<%=@category["country"]%>
<%=@category["currency"]%>
<%=@category["usd"]%>
<%=@category["client_key"]%>
<%=@category["client_name"]%>
<%=@category["client_email"]%>
<%=@category["client_phone"]%>
<%=@category["product_tier"]%>
<%=@category["brand_logo_large"]%>
0
ответ дан kiddorails 17 January 2019 в 05:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: