草庐IT

json_parser

全部标签

javascript - 如何在 JavaScript 中将 JSON 对象字符串化为负零?

如何使用JSON.stringify将负零转换为字符串(-0)?似乎JSON.stringify将负零转换为表示正一的字符串。有好的解决方法吗?varjsn={negative:-0};isNegative(jsn.negative)?document.write("negative"):document.write("positive");varjsonString=JSON.stringify(jsn),anotherJSON=JSON.parse(jsonString);isNegative(anotherJSON.negative)?document.write("negati

javascript - 如何在JSON.stringify : Uncaught TypeError: Converting circular structure to JSON?中找到循环结构

当我在大型结构上遇到UncaughtTypeError:ConvertingcircularstructuretoJSON时,很难找出循环引用的确切位置。是否有一种简单的方法来查找/调试数据结构中的循环元素? 最佳答案 我还没有找到一个简单的方法来做到这一点,其他人似乎建议在JSON.stringify中使用自定义替换函数来控制访问了哪些属性。我试图写这样的替代品:functiondetector(obj){functioncollector(stack,key,val){varidx=stack[stack.length-1].i

javascript - AngularJS JSON 漏洞保护是如何工作的?

angular网站建议在您的JSON前加上)]}'\n前缀,以防止它们被称为JSONP:AJSONvulnerabilityallowsthirdpartywebsitetoturnyourJSONresourceURLintoJSONPrequestundersomeconditions.TocounterthisyourservercanprefixallJSONrequestswithfollowingstring")]}',\n".AngularwillautomaticallystriptheprefixbeforeprocessingitasJSON.但是引用的文章没有提到

javascript - 如何从 jSon 对象构建数组

我正在尝试从JSON数组构建2个数组。{"2015-03-24":{"bind":0,"info":"","notes":"","price":"150","promo":"","status":"available"},"2015-03-25":{"bind":0,"info":"","notes":"","price":"150","promo":"","status":"available"},"2015-03-26":{"bind":0,"info":"","notes":"","price":"150","promo":"","status":"available"},"20

javascript - 第一次请求加载json数据并显示在首页

我是第一次使用Vue.js。我需要序列化django的对象views.pydefarticles(request):model=News.objects.all()#gettingNewsobjectslistmodelSerialize=serializers.serialize('json',News.objects.all())random_generator=random.randint(1,News.objects.count())context={'models':modelSerialize,'title':'Articles','num_of_objects':News

javascript - 节点和浏览器在 package.json 中的不同主要入口点

在同构React应用程序中,我有myModule,它在节点和浏览器环境中的行为应该不同。我想在package.json中为myModule配置这个分割点:package.json{"private":true,"name":"myModule","main":"./myModule.server.js","browser":"./myModule.client.js"}文件结构├──myModule│ ├──myModule.client.js│ ├──myModule.server.js│└──package.json│├──browser.js└──server.js所以当我在no

javascript - 使用 Fetch API 获取 json 格式的闪烁提要

我设法通过使用$.getJSON从闪烁提要api获取json响应,但是当我尝试使用Fetch进行此操作时,我似乎只得到XML响应。这有效:varflickerAPI="http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";$.getJSON(flickerAPI,{tags:"searchTerm",tagmode:"any",format:"json"}).done(function(data){//....});这不起作用:varflickerAPI="http://api.flickr.com

javascript - 使用 TypeScript 函数返回 JSON 对象

我最近发现了TypeScript,并尝试将我现有的JavaScript代码转换为TypeScript。我有一个函数可以从字符串(data)中检索信息,将其放入JSON对象(json)中并返回它。但是,当使用TypeScript且未指定返回类型时,我在Eclipse中收到以下错误:Nobestcommontypeexistsamongreturnexpressions当我添加any返回类型时它就消失了,但我认为这不是一个好的解决方案(太通用)。而且我找不到“json”或“object”类型。我的问题是:我应该使用什么返回类型?函数如下:functionformaterDonnees(da

javascript - 在客户端绑定(bind) JSON 数据时如何避免 'null' 字符串

在将JSON数据绑定(bind)到HTMLUI时,是否可以避免客户端出现“NULL”字符串?我正在使用ASP.NETMVC+jQuery+jTemplates.数据来自linq-to-sql类,这些类有很多可为null的属性。当这些属性被序列化并传输回客户端时,我最终得到这样的JSON:[{"Id":1,"SuitId":1,"TypeId":null,"Type":null,"CourtId":null,"Court":null}]为什么我将此数据绑定(bind)到HTML我有很多“NULL”字符串。我已经尝试过手动绑定(bind)和JavaScript模板引擎(jTemplate)

javascript - 为 mvc 绑定(bind)展平复杂的 json 对象

我的Controller正在像这样以json格式将对象图返回给ViewreturnJson(customer);在View中我的json对象看起来像这样{Name:'Joe',Budget:{Amount:500,Spend:100}}哪个正确映射到我的客户对象:publicclassCustomer{publicstringName{get;set;}publicBudgetBudget{get;set;}}publicclassBudget{publicdecimalAmount{get;set;}publicdecimalSpend{get;set;}}我想将同一个json对象传