我正在使用.net web api获取json并将其返回到前端以获得角度.json可以是对象或数组.我的代码目前只适用于数组而不是对象.我需要找到一种方法来tryparse或确定内容是对象还是数组.
这是我的代码
public HttpResponseMessage Get(string id)
{
string singleFilePath = String.Format("{0}/../Data/phones/{1}.json", AssemblyDirectory, id);
List<Phone> phones = new List<Phone>();
Phone phone = new Phone();
JsonSerializer serailizer = new JsonSerializer();
using (StreamReader json = File.OpenText(singleFilePath))
{
using (JsonTextReader reader = new JsonTextReader(json))
{
//if array do this
phones = serailizer.Deserialize<List<Phone>>(reader);
//if object do this
phone = serailizer.Deserialize<Phone>(reader);
}
}
HttpResponseMessage response = Request.CreateResponse<List<Phone>>(HttpStatusCode.OK, phones);
return response;
}
Run Code Online (Sandbox Code Playgroud)
以上可能不是这样做的最佳方式.它就在我现在的位置.
我的页面顶部有大约20像素的空白区域.我检查了每个元素,这个区域没有任何填充或边距.当我检查身体元素时,它不包括这个空间.当我检查html元素时确实包含了这个空间.如果我删除
<!DOCTYPE html>
Run Code Online (Sandbox Code Playgroud)
白色的空间消失了.
这是我的主要布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@RenderSection("Css", false)
</head>
<body>
@RenderSection("JavaScript", false)
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我参与了几个不同的项目,我已经看到了两种创建jQuery/JavaScript函数的方法.
首先:
function testFunction(){
};
Run Code Online (Sandbox Code Playgroud)
第二:
var testFunction = function (){
};
Run Code Online (Sandbox Code Playgroud)
这些之间有区别吗?
我在一家企业级SaaS公司工作.该产品是现场产品,在开发方面约为6个月.显而易见,我们作为公司和产品仍处于起步阶段.
我们的一个项目人员购买了他在网上找到的主题.它有一些很好的图像,但除此之外,它主要是垃圾.用于ui的唯一其他附加组件是jquery ui.我想有必要提一下我们使用Microsoft堆栈(C#,MVC3,Visual Studio).我们还涉足Html5和Css3.
最近我从我的开发朋友那里听到了很棒的引导,如何不使用它是愚蠢的顶峰.我想将引导程序用于公司中的其他人,但我希望首先从SO社区获得反馈.
转换的优点/缺点是什么?你会推荐吗?如果是,你会有多难推动开关?
我想在我的日期库中更新一行.问题是,通过我的错误,我有两行相同的数据.如何在一行上运行更新?
我有以下html:
<div>
<input type="text" maxlength="2" class="day-spin-month"></input>
<span>/</span>
<input type="text" maxlength="2" class="day-spin-day"></input>
<span>/</span>
<input type="text" maxlength="4" class="day-spin-year"></input>
</div>
Run Code Online (Sandbox Code Playgroud)
我试图将焦点转移到下一个输入.我有以下两种方式工作.
$('.day-spin-month').on('keyup', function () {
if (this.value.length >= 2) {
$(this).next().next().focus();
}
});
$('.day-spin-day').on('keyup', function () {
if (this.value.length >= 2) {
$(this).next().next().focus();
}
});
Run Code Online (Sandbox Code Playgroud)
小提琴:http://jsfiddle.net/dan_vitch/JbQaN/1/
$('.day-spin-month').on('keyup', function () {
if (this.value.length >= 2) {
var test=$(this).next()
var test2= $(test).next('input');
test2.focus();
}
});
$('.day-spin-day').on('keyup', function () {
if (this.value.length >= 2) {
var test=$(this).next()
var test2= $(test).next('input');
test2.focus();
}
}); …
Run Code Online (Sandbox Code Playgroud) 我使用IDataReader来调用没有参数的存储过程.当参数存在时,我没有找到如何执行此操作的示例.IDataReader是否处理存储过程的参数?
请举个例子.
HTML
<a onclick="testGetParametersDynamic2();">fill in names and check it out</a>
<br />
<p>Enter First Name</p>
<input id="myFirstName" type="text" />
<br />
<p>Enter Last Name</p>
<input id="myLastName" type="text" />
<div id="outputGET3"></div>
Run Code Online (Sandbox Code Playgroud)
C#
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public string testGetParametersDynamic(string firstName, string lastName)
{
string fullName = firstName + lastName;
return fullName;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了多种输入数据的方法bc我认为这就是问题所在
尝试1
function testGetParametersDynamic2()
{
$.ajax(
{
post: 'GET',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: '{"firstName":"' + $('#myFirstName').val() + '","lastName":' +
$('#myLastName').val() + '"}',
url: 'UtilitieService.asmx/TestGetParametersDynamic',
success: function …
Run Code Online (Sandbox Code Playgroud) 我已经阅读过这篇文章了,但是我不知道如何让它能够从用户那里获取数据.这是我正在使用的ajax jquery.我知道(或者至少认为)这个不能让人偏袒.但它一直有效,直到渲染失败.我认为这可能会有所帮助.
$.ajax(
{
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: "{'test':" + "'" + dateText + "'}",
dataType: 'json',
url: 'Site/Grab/',
success: function (result) {
alert('Success');
},
error: function (error) {
alert('Fail');
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的控制器
[HttpPost]
public ActionResult Grab(string test)
{
DateTime lineDate= Convert.ToDateTime(test);
List<Info> myInfo= GameCache.Data(lineDate);
return PartialView("_PartialView", myInfo);
}
Run Code Online (Sandbox Code Playgroud) 我正在阅读本教程.我将此设置作为MVC4项目.这是我使用Vs 2013制作的第一个项目.
当我从phones.json收集json时,我正在迈出这一步.我收到了错误.
HTTP Error 404.3 -Not found
The page you are requesting cannot be served because of extension configuration.
If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
Run Code Online (Sandbox Code Playgroud)
这也是我对json文件的调用
$http.get('Data/Phones/phones.json').success(function (data) {
$scope.phones = data;
})
Run Code Online (Sandbox Code Playgroud)
这是我的文件夹结构的图像
jquery ×4
c# ×3
.net ×1
angularjs ×1
css3 ×1
html ×1
idatareader ×1
iis ×1
javascript ×1
json ×1
razor ×1
sql ×1
sql-server ×1
t-sql ×1