2014-03-12 222 views
1

我正在尝试对我的一个函数进行测试。通过url传递参数?

这是从我的网站外部调用的行为像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; } 
} 

编辑已更改?第二个参数&:


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

改变我的URL到一个以上的一个破发点被击中,但值是不正确之后。

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

+0

当你有多个参数时,你必须用'&'分隔它们。 '?'仅用于将路径名与第一个参数分开。 – Barmar

+0

我正在将Url直接写入我的浏览器,因此我可以发送关于如何创建它的屏幕截图。 – Pomster

+0

对此有何动静?你怎么样? – paqogomez

回答

1

您应该使用符号(&)到多个查询字符串参数分开。就像您使用的那样,您使用的是?,因此“?Id = 4785”被解释为ValuationDetails参数值的一部分。

更正:

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

以秒为单位击败我。 :)不错的工作+1 – paqogomez

+0

@Cory谢谢,修正了,但我的价值仍然是错误的,请参阅我的编辑。 – Pomster

+1

@Pomster:你确定'JSON'你有.NET所期望的'Dictionary '?我对内部运作知之甚少,不太熟悉。另外,第一次测试中的URL中的参数值与您刚刚发布的参数值不同。 –

0

你的URL字符串看起来格式不正确。

对于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

+0

@paqogogomez谢谢但我的价值观仍然是错误的,请参阅我的编辑屏幕截图。 – Pomster

+0

@Pomster你的屏幕截图不显示任何参数的值。发布你用来解析json的代码。 – paqogomez

+0

我正在将它写入我的Url – Pomster

1

我觉得这是更好地编码JSON了。 从那一刻起,你将拥有例如一面你的数据?或&你也会得到一个例外。