我有一个像以下JavaScript对象:
var p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
Run Code Online (Sandbox Code Playgroud)
现在我想通过所有回路p元素(p1,p2,p3...),并得到他们的键和值.我怎样才能做到这一点?
如有必要,我可以修改JavaScript对象.我的最终目标是遍历一些键值对,如果可能的话,我想避免使用eval.
我试图将一个JSON对象发布到asp.net webservice.
我的json看起来像这样:
var markers = { "markers": [
{ "position": "128.3657142857143", "markerPosition": "7" },
{ "position": "235.1944023323615", "markerPosition": "19" },
{ "position": "42.5978231292517", "markerPosition": "-3" }
]};
Run Code Online (Sandbox Code Playgroud)
我使用json2.js来串行我的json对象.
我正在使用jquery将其发布到我的webservice.
$.ajax({
type: "POST",
url: "/webservices/PodcastService.asmx/CreateMarkers",
data: markers,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
"无效的JSON原语:
我发现了一堆与此相关的帖子,这似乎是一个非常常见的问题,但我没有尝试解决这个问题.
当firebug发布到服务器的内容时,它看起来像这样:
标记%5B0%5D%5Bposition%5D = 128.3657142857143&标记%5B0%5D%5BmarkerPosition%5D = 7&标记%5B1%5D%5Bposition%5D = 235.1944023323615&标记%5B1%5D%5BmarkerPosition%5D = 19&标记%5B2%5D%5Bposition% 5D = 42.5978231292517&标记%5B2%5D%5BmarkerPosition%5D = -3
我正在调用的webservice函数是:
[WebMethod]
public string CreateMarkers(string markerArray)
{
return "received markers";
}
Run Code Online (Sandbox Code Playgroud) 我想在C#中将自定义格里高利日期转换为波斯日期.例如,我有一个包含此内容的字符串:
string GregorianDate = "Thursday, October 24, 2013";
Run Code Online (Sandbox Code Playgroud)
现在我希望:
string PersianDate =پنجشنبه2آبان1392;
要么
string PersianDate = 1392/08/02
谢谢
我们可以使用.formData()的Body混入到返回FormData的数据表示铬(铬)60+和Firefox 39+
相关规格:
勘误表
有关
如何multipart/form-data在客户端和服务器上使用JavaScript 手动创建以multipart/form-data作为响应?
我的服务器使用 .Net Core 2.1.402
这是我的 C# 类:
public class SampleDetailsDto
{
public Guid Id{ get; set; }
public string Text { get; set; }
public IEnumerable<string> ImageUrls { get; set; }
public IFormCollection Images { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的 C# 控制器
[HttpPut]
[Route("{id:guid}")]
public async Task<IActionResult> UpdateAsync([FromRoute]Guid id, [FromForm] SampleDetailsDtodto)
{
Console.WriteLine(dto.Text);
Console.WriteLine(dto.Images.Length);
return OK();
}
Run Code Online (Sandbox Code Playgroud)
我使用 nswag 生成客户端服务,但目前存在一个错误(https://github.com/RSuter/NSwag/issues/1421#issuecomment-424480418)上传多个文件,所以我扩展了更新方法来创建我的,这里是代码:
public update(id: string, dto: SampleDetailsDto | null | undefined): Observable<SampleDetailsDto | null> {
let url_ = this._baseUrl + …Run Code Online (Sandbox Code Playgroud) javascript ×2
ajax ×1
angular ×1
asp.net-core ×1
c# ×1
date ×1
each ×1
jquery ×1
json ×1
loops ×1
nswag ×1
persian ×1
typescript ×1
web-services ×1