[英]how to get value from javascript object in c#
I am sending data from a web based application to a WCF RESTful service. 我正在将数据从基于Web的应用程序发送到WCF RESTful服务。
The value that I am sending is [object Object]
but I am struggling to figure out how to convert the value in C# to be able to use the real value. 我要发送的值是[object Object]
但我正在努力弄清楚如何在C#中转换值以能够使用实际值。
when logged the value [object Object]
is Object {a: "GBasQLwJcDidphr/1Chumg=="}
. 记录时,值[object Object]
是Object {a: "GBasQLwJcDidphr/1Chumg=="}
。
You've to use: 您必须使用:
var json = JSON.stringify(YourObject);
And pass this in request. 并通过请求。
Then at server side, Add a reference of Newtonsoft.Json.dll and use
JsonConvert` to deserialize the json string into object as 然后在服务器端,添加对Newtonsoft.Json.dll and use
的引用, Newtonsoft.Json.dll and use
JsonConvert`将json字符串反序列化为object作为
var targetObject = JsonConvert.DeserializeObject<TypeOfTargetObject>(jsonString);
On client side: 在客户端:
var json = JSON.stringify(objectToSend);
On Server side: 在服务器端:
var data = JsonConvert.DeserializeObject<Example>(jsonString);
public class Example
{
public string a { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.