简体   繁体   English

JSON解析错误和响应日历

[英]JSON Parsing error and Responsive Calendar

I have a problem passing events to Responsive calendar ( http://w3widgets.com/responsive-calendar/ ). 我在将事件传递到响应日历( http://w3widgets.com/sensitive-calendar/ )时遇到问题。 I try to create a simple object with a calendar date. 我尝试创建一个带有日历日期的简单对象。 For your convenience I simplified the script to the following: 为了您的方便,我将脚本简化为以下内容:

 /* Create calendar events object*/

 appointment="2014-01-25"; 
 var options={"badgeClass":"badge-warning", "url": ""};

 var str = "{'" + appointment + "':{'badgeClass':'badge-warning'}}";
 var test2=JSON.parse(str);

 /* Initialize calendar */
  $(".responsive-calendar").responsiveCalendar({
  time: '2014-01',
  events: test2
  });

If I use 如果我用

var test={'2014-04-25': options};

the calendar highlights the specified date. 日历突出显示指定的日期。 Nevertheless, the parsed string produces an "Unexpected token ' " error. 但是,已分析的字符串会产生“意外令牌'”错误。 I couldn't think of a better way to create the object, since I get the dates dynamically. 我想不出更好的方法来创建对象,因为我可以动态获取日期。 Any ideas? 有任何想法吗? Thank you in advance for your answers. 预先感谢您的回答。 :) :)

Just in case this is useful to anyone, the problem was double quotes. 以防万一这对任何人都有用,问题是双引号。 The correct syntax is 正确的语法是

 var str = '{"' + appointment + '":{"badgeClass":"badge-warning"}}';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM