js操做object、Array、json總結

1、[]與array的區別javascript

在JS中,[]表示數組,{}表示對象;通常在JSON中使用;
例如:var json={"eles":["aaa","bbb","ccc","ddd"]};
表示對象json的eles屬性的值爲一個四個元素的數組;
能夠經過json.eles[0]、json.eles[1]...來獲取這些值。。。
另外,var arr = new Array();在js中其實能夠等價於var arr = [];java

2、解析的例子node

{"name":"政治安全時間趨勢圖","type":"linechart","statonfield":"IR_URLDATE","description":"由圖可知,政治安全時間趨勢圖事件中經過各個類別的對比走勢來看較爲交錯。其中,新聞的關注於2018年09月13日達到最高峯,信息量爲13。","records":[{"label":"新聞","values":[13,11,4,5,5,0,0],"extremumpoints":[]},{"label":"論壇","values":[2,19,3,0,0,0,0],"extremumpoints":[1]},{"label":"微信","values":[6,3,4,2,5,0,0],"extremumpoints":[2,4]},{"label":"博客","values":[0,0,0,0,0,0,0],"extremumpoints":[]}],"ticks":["2018.09.13","2018.09.14","2018.09.15","2018.09.16","2018.09.17","2018.09.18","2018.09.19"]}
function echarts03(url,idiv,numDiv)
{
	
	var node=new Array();
	
	$.ajax({
	  type: 'GET',
	  url:url,
	  dataType: 'jsonp',
	  async:false,
	  success: function(data){
console.info(data);		  
	  var x=data.ticks;
	  var records=data.records;
	  var y =[];
	  var num=0;
	  
	  
	var array=new Array();
	  for(var i=0;i<records.length;i++)
	{
		
		
		var obj={};
		obj["name"]=records[i].label;
		obj["data"]=records[i].values;
		obj["type"]="bar";
		
		array.push(obj);
	}
	  console.info(obj.data);
	  for(var i in obj.data)
	  {
		  num+=parseInt(obj.data[i]);
	  }
	  var vdivid="#"+numDiv;
	  $(vdivid).text(num);

3、JSONObject與JSONArrayajax

相關文章
相關標籤/搜索