发送JSON集合ASMX web服务 [英] Sending JSON collection to ASMX webservice

查看:313
本文介绍了发送JSON集合ASMX web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个类



 公共类DesignElements 
{
酒店的公共列表< D​​esignElement>元素;
公共BOOL接待{设置;得到; }
公共字符串的ThemeID {设置;得到; }


公共DesignElements()
{
元素=新的List< D​​esignElement>();
}
}序列化这个类页的



结果是:

  VAR JSON = 
{
元素:
[
{对齐:空,大胆:虚假}
{对齐:空,大胆:虚假}
],
阵线:真实,
的ThemeID :9
};



问题是,在页面发送此JSON到Web服务使用jQuery




  1. 我应该使用 JSON.stringify 方法,把它一样字符串?如果是的话是什么web服务参数的名称?


  2. 我可以发送JSON作为 DesignElements 对象的Web服务。如果是的话是什么web服务参数的名称?



解决方案

正如我在一些搜索特意在阿贾克斯jQuery的JSON发布到了web服务



首先,我要我的对象转换为JSON:

 数据: {DesignElements:JSON.stringify(JSON)} $​​ b $ b  

和张贴它webserivce

  [的WebMethod] 
公共无效SaveJson(DesignElements DesignElements)
{
}


I have this class :

public class DesignElements
{
    public List<DesignElement> Elements;
    public bool Front { set; get; }
    public string ThemeID { set; get; }


    public DesignElements()
    {
       Elements = new List<DesignElement>();
    }
}

result of serializing this class to page is :

var json=
         {
            "Elements":
               [
                {"Alignment":null,"Bold":false},
                {"Alignment":null,"Bold":false}
               ],
               "Front":true,
                "ThemeID":"9"
        };

problem is sending this json in page to web-service with jQuery

  1. should I use the JSON.stringify method and sent it as as string ? if yes what is the name of argument in web-service ?

  2. can I send json as DesignElements object to web-service. if yes what is the name of Argument in web-service ?

解决方案

as I got in the some search specially in Jquery Ajax Posting json to webservice

First I have to convert my object to JSON :

data: {DesignElements : JSON.stringify(json)}

and post it to webserivce

    [WebMethod]
    public void SaveJson(DesignElements DesignElements)
    {
    }

这篇关于发送JSON集合ASMX web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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