我有一个链接,在broswer 中打开json数据但不幸的是我不知道如何阅读它.有没有办法使用javascript逗号分隔(csv)格式转换此数据并将其保存在javascript变量中.我刚刚开始学习并且对json完全没有任何线索,如果有人可以为它编写脚本会很棒.
数据似乎如下:
{
"count": 2,
"items": [{
"title": "Apple iPhone 4S Sale Cancelled in Beijing Amid Chaos (Design You Trust)",
"description": "Advertise here with BSA Apple cancelled its scheduled sale of iPhone 4S in one of its stores in China\u2019s capital Beijing on January 13. Crowds outside the store in the Sanlitun district were waiting on queues overnight. There were incidents of scuffle between shoppers and the store\u2019s security …Run Code Online (Sandbox Code Playgroud) 我有这样的课;
public class MyStok
{
public int STId { get; set; }
public int SM { get; set; }
public string CA { get; set; }
public string Br { get; set; }
public string BNo { get; set; }
public decimal Vat { get; set; }
public decimal Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我像这样deserilala;
string sc= e.ExtraParams["sc"].ToString();
MyStok myobj = JSON.Deserialize<MyStok>(sc);
Run Code Online (Sandbox Code Playgroud)
我的输出似乎喜欢这个(字符串sc)在fiddler上
[
{
"STId": 2,
"CA": "hbh",
"Br": "jhnj",
"SM": 20,
"Vat": 10,
"Price": 566,
"BNo": "1545545" …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下html但我无法让它工作.
<div class=" flex-center">
<div class="flex-item-center">
<p>
Some text in box A
</p>
</div>
<div class="flex-item-bottom">
<p>Some text in box B....</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.flex-center {
display: flex;
align-items: center;
align-content: center;
justify-content: center;
}
.flex-item-center {
align-self: center;
}
.flex-item-bottom {
align-self: flex-end;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它看起来像图像?
我目前能够使用SQL Server的"OPENJSON WITH(..."语法解析大部分JSON文件.但是,这个特定的文件包含我不知道如何处理的嵌套数组.
我读过的许多例子都将JSON引用为变量.在这种情况下,我正在调用一个文件:
select DEV_JSON.*
from OPENROWSET
(BULK 'C:\Users\Myuser\Documents\JSON_extract.json', SINGLE_CLOB) as my_datafile
CROSS APPLY OPENJSON(BulkColumn)
WITH
(DOC_ID varchar(100) '$.doc._id',
DOC_REV varchar(45) '$.doc._rev',
DELY_APPL_NAME varchar(20) '$.doc.delivery.application',
DELY_SENT_BY varchar(25) '$.doc.delivery.sender.id',
DELY_SENT_TYPO varchar(20) '$.doc.delivery.sender.type',
.....
....
...
..) as DEV_JSON
Run Code Online (Sandbox Code Playgroud)
其中一个属性包含嵌套数组.下面我复制了我的JSON的前5个属性,以及嵌套的"recipients"数组.
如何构建我的SQL来解析这一部分?
"doc": {
"_id": "049d4e4030afcdeefedaa90f640f91d4a2be93d7-bd_abcxyz@somemail.com",
"_rev": "3-e119db13dae8d50ae0c4579ba9c87fc9",
"delivery": {
"application": "App_XYZ",
"sender": {
"id": "MABarrera@yahoo.com",
"type": "user"
},
"recipients": [{
"type": "email",
"recipient": "\"Artzer, Daniel J\" <DJArtzer@emailaddr.com>",
"sentTS": "2017-10-18T13:04:00.133Z"
},
{
"type": "email",
"recipient": "\"Higgins, Laura L\" <LLHiggins@emailaddr.com>",
"sentTS": "2017-10-18T13:04:00.133Z"
}, …Run Code Online (Sandbox Code Playgroud) 可以使用本机javascript获取本地化的完整月份名称.
var objDate = new Date("10/11/2009"),
locale = "en-us",
month = objDate.toLocaleString(locale, { month: "long" });
Run Code Online (Sandbox Code Playgroud)
但这仅获取给定日期的月份数.我只想让月份名称对应一个月号.例如,如果我这样做getMonth(2)会返回February.如何getMonth使用本机javascript实现(没有类似的库moment)?
我正在尝试为控制器中的事件编写单元测试.
以下是我的控制器
myApp.controller('ParentCtrl', ['$scope', function ($scope) {
$scope.message = "Some text in parent";
$scope.$on("update_parent_controller", function(event, message){
$scope.message = message;
});
}])
.controller('ChildCtrl', ['$scope', function ($scope) {
$scope.clickFunction = function() {
$scope.message = "Parent updated from child controller";
$scope.$emit('update_parent_controller', $scope.message);
}
}]);
Run Code Online (Sandbox Code Playgroud)
以下是我试图写的测试
describe("Hello Controller Test", function () {
var ctrl, scope;
beforeEach(module("myApp"));
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
spyOn(scope, '$on');
ctrl = $controller("ParentCtrl", {
$scope : scope
});
}));
it('should change ParentCtrl message property from child ctrl', function (){ …Run Code Online (Sandbox Code Playgroud) 我有一系列元素:
var elements = ['div', 'a', 'p', 'foo']
我也有一系列属性:
var attributes = ['src', 'href', 'quux', 'id']
我想了解如何验证以上各项的组合是否可以构成有效的DOM对象。
或者,换句话说:
如何针对DOM模式验证DOM对象?*
例如(基于上述元素和属性):
DOM_result = '<div src />'; // = false
DOM_result = '<div href />'; // = false
DOM_result = '<div quux />'; // = false
DOM_result = '<div id />'; // = true
DOM_result = '<a src />'; // = false
DOM_result = '<a href />'; // = true
DOM_result = '<a quux />'; // = false
DOM_result = '<a …Run Code Online (Sandbox Code Playgroud) 在Home.aspx中有一个脚本:
<script type="text/javascript">
function probarAjax() {
var Publicaciones = {
"Categoria": "Noticia"
}
$.ajax({
type: "POST",
url: "Controlador.ashx?accion=enviar",
data: JSON.stringify(Publicaciones),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
console.log(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
在Controlador.ashx里面:
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/json";
var categoria = string.Empty;
JavaScriptSerializer javaSerialize = new JavaScriptSerializer();
categoria = context.Request["Categoria"];
var capaSeguridad = new { d = categoria };
context.Response.Write(javaSerialize.Serialize(capaSeguridad));
}
Run Code Online (Sandbox Code Playgroud)
结果是:
Object {d: null}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?如果我在Publicaciones带有值的变量的数据中发送参数"Noticia" …