通过url传递参数?

时间:2014-03-12 13:21:23

标签: c# json web-services url parameter-passing

我正在尝试测试对我的一个函数的调用。

这是从我的网站外部调用的,就像Web服务一样。

测试我试图通过我的网址传递参数。

  

http://localhost:0000/APIService/UploadValuationDetails?ValuationDetails=[ {property_details_address_address1 {TagValue:'测试'},{ImageBase64:''}}?]编号= 4785

我服务中的代码:

public void UploadValuationDetails(Dictionary<string, ValuationDetails> JsonResult, int Id)
{
  DatabaseHelper DBH = new DatabaseHelper();

  foreach (var item in JsonResult)
  {                               //(ValuationId , TagName , TagValue , ImageBase64)
    DBH.WSValuationDetailUpdate(Id, item.Key, item.Value.TagValue, item.Value.ImageBase64); 
  }         
}

ValuationDetails类:

public class ValuationDetails
{
   public string TagValue { get; set; }
   public string ImageBase64 { get; set; }
}

编辑已更改?对于&amp;的第二个参数:


> http://localhost:0000/APIService/UploadValuationDetails?ValuationDetails={'property_details_address_address1':[{TagValue:'Test',ImageBase64:''}]}&Id=4785

将我的网址更改为上面的网址后,点击了一个断点但值不正确。

enter image description here

编辑2尝试在json结果中获取正确的值。


我想我离我更近了:

http://localhost:0000/APIService/UploadValuationDetails?JsonResult={TagName:"property_details_address_address1",ValuationDetails:{TagValue:"Test","ImageBase64:""}}]&Id=4785

但现在我的jsonResult = 0

3 个答案:

答案 0 :(得分:1)

您应该使用&符号(&)来分隔多个查询字符串参数。如你所知,你正在使用?,所以&#34;?Id = 4785&#34;被解释为ValuationDetails参数值的一部分。

修正:

                                       this is correct ┐
                                                       ↓
http://localhost:0000/APIService/UploadValuationDetails?ValuationDetails=
 [{property_details_address_address1{TagValue:'Test'},{ImageBase64:''}}]&Id=4785
                                                                        ↑
                                               but this should be fixed ┘

答案 1 :(得分:1)

我认为编码JSON也更好。 从那时起你将拥有数据的那一刻?或者&amp;你也会得到一个例外。

答案 2 :(得分:0)

您的网址字符串看起来格式不正确。

对于URL的分隔符和您将使用的参数?

但要使用&

分隔参数
  

的http://本地主机:0000 / APIService / UploadValuationDetails ValuationDetails = [{property_details_address_address1 {TagValue: '测试'},{ImageBase64: ''}}]和ID = 4785

您的JSON无效。

我已经使用了一点,但它仍然需要你的输入。

[
    {
        "property_details_address_address1": {
            "TagValue": "Test"
        },
        "needs_a_name_here": {
            "ImageBase64": ""
        }
    }
]

请注意,我在名字旁边加了引号。而你的第二个对象也需要一个名字。

我使用JSONLint验证并创建了正确的json

相关问题