草庐IT

day33-JSON

全部标签

javascript - 如何将 JSON 字符串分配给 Javascript 变量?

将JSON字符串分配给变量的正确方法是什么?我不断收到EOF错误。varsomejson="{"key1":"val1","key2":"value2"}";http://jsfiddle.net/x7rwq5zm/1/ 最佳答案 你没有正确逃脱。你确保你做到了:varsomejson="{\"key1\":\"val1\",\"key2\":\"value2\"}";更简单的方法是使用JSON.stringify()将现有对象转换为字符串。会尽可能推荐这个,因为出现打字错误的可能性很小。varobj={key1:"val1",ke

javascript - 将 json 对象转换为数组以使用 Javascript 遍历 ng-repeat?

这个问题在这里已经有了答案:WhatiseasywaytoconvertobjectinarrayAngularJS?(3个答案)关闭6年前。这是我的示例json,我从firebase获取我的jsonobj我必须将列表转换为数组以通过ng-repeat绑定(bind)到html中。我的Json对象是{"cats1":{"Name":"cricket","imgUrl":"someurl","list1":{"bat":{"Name":"bat","imgUrl":"someurl","price":"$100"},"pads":{"displayName":"pads","imgUrl

JavaScript - 构建 JSON 对象

我正在尝试了解如何在JavaScript中构建JSON对象。此JSON对象将传递给JQueryajax调用。目前,我正在硬编码我的JSON并进行JQuery调用,如下所示:$.ajax({url:"/services/myService.svc/PostComment",type:"POST",contentType:"application/json;charset=utf-8",data:'{"comments":"test","priority":"1"}',dataType:"json",success:function(res){alert("Thankyou!");},er

javascript - 将查询字符串反序列化为 JSON 对象

试图找到如何从?...&foo=bar&...制作{foo:"bar"}但谷歌搜索并只得到jQuery.params做相反的事情。请提出任何建议(内置的javascript函数、jQuery、Underscore.js-都行)?或者,我是否需要自己实现(不是很麻烦,只是尽量避免重新发明轮子)? 最佳答案 实际上@talsibony的上述回答没有考虑查询字符串数组(例如test=1&test=2&test=3&check=wow&such=doge)。这是我的实现:functionqueryStringToJSON(qs){qs=qs

javascript - 如何检测 JavaScript 中的 JSON 支持?

我尝试使用if(JSON.parse){}检测JSON支持,但它不起作用。有什么方法可以检测JSON支持吗? 最佳答案 取自最著名的json实现https://github.com/douglascrockford/JSON-js/blob/master/json2.jsvarJSON;if(JSON&&typeofJSON.parse==='function'){....}(我合并了两个if:第163行的if(!JSON){和if(typeofJSON.parse!=='function'){第406行。这里的技巧是varJSON

javascript - JSON 解析问题

我是jQuery中JSON解析的完全菜鸟。以为我得到了回应......我的数据是这种形式:Array([1]=>abc,[3]=>mango,[4]=>apple,[5]=>fruits)通过这种方式,我希望此列表显示为自动完成列表。我正在使用。jQuery("#name").autocomplete('',{multiple:true,mustMatch:true,matchContains:true,autoFill:false,dataType:"json",parse:function(data){returnjQuery.map(data,function(item){ret

javascript - 从 json 数组中删除数据

我正在尝试从json数组中删除一段数据。例如我有这个数组varfavorites={"userID":"12345678","favorites":[{"name":"MyFavorites","id":"87654321","items":[{"productID":"11234567","added":"TIMESTAMP","title":"Project","type":"WeekendProject","imageURL":"1"},{"productID":"11223456","added":"TIMESTAMP","title":"Bathroom","type":"W

javascript - xmlhttprequest responsetext 来接受 header : text/xml , 但应用程序/JSON 的服务器错误

我必须从资源索引页面获取响应文本作为JSON对象。当我不在请求中放置Acceptheader时,它会向我显示xml响应(我在警报中看到它)..但我希望将响应作为JSON对象。我该怎么办。一种解决方案是httpRequest.setRequestHeader('Accept','application/JSON');但这给了我一个服务器错误:500还说AmessagebodywriterforJavatype,class....,andMIMEmediatype,application/octet-stream,wasnotfound有人可以建议如何克服这个问题并获得JSON格式的响应吗

javascript - jQuery 日期选择器 : restrict date selection based on week day

是否可以修改jQueryUIDatepicker以仅允许用户选择,例如,星期一? 最佳答案 给你:星期一是不可选择的:$(document).ready(function(){$('input').datepicker({beforeShowDay:function(date){return[date.getDay()!=1,''];}});});您可以在这里玩的功能示例:http://jsfiddle.net/RaYZ5/19/.API文档:http://docs.jquery.com/UI/Datepicker#event-be

javascript - 从 jQuery 或 JS 中的 json 对象中提取数据

我想使用https://raw.github.com/currencybot/open-exchange-rates/master/latest.json提供的货币数据作为初始测试,我创建了它的简化版本作为内联对象:varobj=[{"disclaimer":"Thisdataiscollectedfromvariousprovidersandprovidedfreeofchargeforinformationalpurposesonly,withnoguaranteewhatsoeverofaccuracy,validity,availability,orfitnessforanyp