如何在休息Web服务中发送JSON数据? [英] How to send the JSON data in rest web services?

查看:126
本文介绍了如何在休息Web服务中发送JSON数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在休息Web服务中发送JSON数据?
我有一个json对象,其中包含产品ID,商店ID,价格,产品单位,数量
values.Here除产品单位价值外,所有值均为整数。
现在,我想将这些值发送到其他Web服务。
您能提供任何样品或任何有价值的建议吗?

How to send the JSON data in rest web services? I have a json object which contains product Id,store Id,price,product Unit,quantity values.Here All the values are integer only except product Unit value. Now, I want to send these values into rest web services. Could you please give any samples or any valuable suggestions?

推荐答案

由于您已使用Worklight标记对其进行了标记,因此我假设您打算询问如何发送json数据从worklight客户端到外部REST服务。要在Worklight中执行此操作,您需要使用Worklight HTTP适配器。请参阅此处的文档: http: //public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v600/04_02_HTTP_adapter_-_Communicating_with_HTTP_back-end_systems.pdf

Since you have tagged this with the Worklight tag, I'm going to assume you meant to ask how to send json data from a worklight client to an external REST service. In order to do this in Worklight, you need to use a Worklight HTTP adapter. See the documentation here: http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v600/04_02_HTTP_adapter_-_Communicating_with_HTTP_back-end_systems.pdf

创建后在Worklight适配器中,您可以从客户端发送您的JSON数据,如下所示:

After creating the Worklight adapter, you can then send your JSON data from the client like this:

/**********************************************************************************
*                           Http Adapter call
**********************************************************************************/
function callAdapter(){

    var myJSONObject = {
        productId: 123, 
        storeId: 123, 
        price: 342, 
        productUnit: "myUnit",
        quantity: 4
    };

    var invocationData = {
            adapter : 'MyHttpAdapter',
            procedure : 'myAdapterProcedure',
            parameters : [myJSONObject]
    };

    WL.Client.invokeProcedure(invocationData, {
        onSuccess : success,
        onFailure : failure
    });
}

function success(response){
    console.log("adapter Success");
    console.log(response);
}

function failure(response){
    console.log("adapter Failure");
    console.log(response);
}

这篇关于如何在休息Web服务中发送JSON数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆