Data Format Rollup-js

Source: Internet
Author: User

createtime--2016 October 12 09:28:09
Author:marydon
Data Format Summary
First, the data format introduction
Standard JSON format--{"key": Value, "key": Value, "Key": Value} (the value can be a number, no double quotation marks, or it can be a string, you need double quotation marks; A value can also contain an object)
Format one: The value stores multiple objects

{"Data": [{"term": "First period", "Wangwu": 199, "LISI": 229, "Zhaoliu": 233, "Sanqi": 234, "Zhangsan": 233},{"term": "Phase II", "Wangwu ": 156," LISI ": 186," Zhaoliu ": 179," Sanqi ": 206," Zhangsan ": 234},{" term ":" Phase III "," WANGWU ": 133," LISI ": 161," Zhaoliu ": 246 , "Sanqi": 185, "Zhangsan": 240},{"term": "Fourth", "Wangwu": 194, "LISI": 126, "Zhaoliu":, "Sanqi": 207, "Zhangsan": 229},{ "term": "Fifth", "Wangwu": 149, "LISI": 166, "Zhaoliu": 209, "Sanqi": 174, "Zhangsan": 197}], "code": 0, "expmsg": "", "MSG": " Operation succeeded "}

Format two: An array of multiple objects

var row = ' [{' term ': ' first period ', ' Wangwu ': 199, ' LISI ': 229, ' Zhaoliu ': 233, ' Sanqi ': 234, ' Zhangsan ': 233},{' term ': ' Phase II ' "," Wangwu ": 156," LISI ": 186," Zhaoliu ": 179," Sanqi ": 206," Zhangsan ": 234},{" term ":" Phase III "," WANGWU ": 133," LISI ": 161," Zhaoliu ": 246," Sanqi ": 185," Zhangsan ": 240},{" term ":" Fourth "," Wangwu ": 194," LISI ": 126," Zhaoliu ": 207," Sanqi " Zhangsan ": 229},{" term ":" Fifth Issue "," Wangwu ": 149," LISI ": 166," Zhaoliu ": 209," Sanqi ": 174," Zhangsan ": 197}] ';

assigning values to arrays

varXaxisvalues = [];//x-axis coordinate valuesvarJsonobj = eval ("(" +row+ ")");//converted to an array of elements of type Object/*This is not possible, and foreach can only traverse the list collection and cannot be used for the iterated group * $ (jsonobj). foreach (function (index,value) {* Shuzu.push (value. (term); *}); *//*It is also not possible to use this iterative approach (JS does not support this iterative approach) * for (Object json:jsonobj) {* Shuzu.push (JSON). term); *}*//*iterating through an array can only use a for loop*/ for(vari = 0; I <jsonObj.length; i++) {Shuzu.push (Jsonobj[i]. term);} Console.log (Shuzu);//["Phase I", "Phase II ", "Phase III", "fourth issue", "phase fifth"]

updatetime--2016 October 25 11:37:09

JSON format value problem
String values in A.json format

var jsonstr = ' {' data ': [{' Fstate ': ' 1 ', ' frcode ': ' 410000 ', ' fzjm ': ' yfbjk ', ' ROWNO ': ' 1 ', ' fremark ': ', ' Fdeptname ":" Preventive Health section "," Fplvcode ":", "Fdeptcode": "},{" Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" Qkylk "," ROWNO ":" 2 ", "Fremark": "", "Fdeptname": "General Medical section", "Fplvcode": "", "Fdeptcode": "},{", "Fstate": "1", "Frcode": "410000", "FZJM": "NK", " ROWNO ":" 3 "," Fremark ":" "," Fdeptname ":" Internal Medicine "," Fplvcode ":" "," Fdeptcode ":" "},{" fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" WK "," ROWNO ":" 4 "," Fremark ":" "," Fdeptname ":" Surgery "," Fplvcode ":", "Fdeptcode": "},{", "Fstate": "1", "Frcode": " 410000 "," FZJM ":" FCK "," ROWNO ":" 5 "," Fremark ":" "," Fdeptname ":" Obstetrics and Gynecology "," Fplvcode ":" "," Fdeptcode ":" "}]," code ": 0," msg ":" Operation succeeded! "," expmsg ":" "}";

Method of taking value

// Fetch Object var jsonobj = eval (' (' +jsonstr+ ') '); Console.log (jsonobj.msg); // take an array element var jsonobj = eval (' (' +jsonstr+ ') '); var jsonObj2 = jsonobj.data;  for (var i = 0; I <jsonObj2.length; i++) {console.log (Jsonobj2[i]. Fdeptname);}

B.json format values

 var  jsonstr = {"Data": [{"Fstate": "1", "Frcode": "410000", "FZJM": "Yfbjk", " ROWNO ":" 1 "," Fremark ":" "," fdeptname ":" Preventive Health section "," Fplvcode ":", "Fdeptcode": "},{", "Fstate": "1", "Frcode": "410000", " FZJM ":" Qkylk "," ROWNO ":" 2 "," Fremark ":" "," Fdeptname ":" General Medical section "," Fplvcode ":" "," Fdeptcode ":"},{"," Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" NK "," ROWNO ":" 3 "," Fremark ":" "," Fdeptname ":" Internal Medicine "," Fplvcode ":" "," Fdeptcode ":" 03 "},{" Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" WK "," ROWNO ":" 4 "," Fremark ":" "," Fdeptname ":" Surgery "," Fplvcode ":" "," Fdeptcode ": "},{" "Fstate": "1", "Frcode": "410000", "FZJM": "FCK", "ROWNO": "5", "Fremark": "", "Fdeptname": "Obstetrics and Gynecology", "Fplvcode": "," Fdeptcode ":"}], "code": 0, "msg": "Operation succeeded!" "," expmsg ":" "}; 
// Fetch Object Console.log (jsonstr.msg); // take an array element // Console.log (jsonstr.data); var jsonObj2 = eval (jsonstr.data);  for (var i = 0; I <jsonObj2.length; i++) {    console.log (Jsonobj2[i]. Fdeptname);}

C.json Array string format values

 var  jsonstr = ' [{"Fstate": "1", "Frcode": "410000", "FZJM": "YFBJK", "ROWNO": "1", "Fremark": "", "fdeptname": "Preventive Health section", "Fplvcode": "," Fdeptcode ":"},{"Fstate": "1", "Frcode": "410000", "FZJM": " Qkylk "," ROWNO ":" 2 "," Fremark ":", "Fdeptname": "General Medical section", "Fplvcode": "," Fdeptcode ":"},{"," Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" NK "," ROWNO ":" 3 "," Fremark ":" "," Fdeptname ":" Internal Medicine "," Fplvcode ":", "Fdeptcode": "},{", "Fstate": "1", " Frcode ":" 410000 "," FZJM ":" WK "," ROWNO ":" 4 "," Fremark ":" "," Fdeptname ":" Surgery "," Fplvcode ":" "," Fdeptcode ":" 04 "},{" Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" FCK "," ROWNO ":" 5 "," Fremark ":" "," Fdeptname ":" Obstetrics and Gynecology "," Fplvcode ":", "Fdeptcode ":"}] '; 
// take an array element var jsonobj = eval (' (' +jsonstr+ ') ');  for (var i = 0; I <jsonObj.length; i++) {    console.log (Jsonobj[i]. FZJM);}

D.json the value of a format array

 var  jsonstr = [{"Fstate": "1", "Frcode": "410000", "FZJM": "YFBJK", "ROWNO": " 1 "," Fremark ":" "," Fdeptname ":" Prevention and Health section "," Fplvcode ":", "Fdeptcode": "},{" Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" Qkylk "," ROWNO ":" 2 "," Fremark ":", "Fdeptname": "General Medical section", "Fplvcode": "," Fdeptcode ":"},{"," Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" NK "," ROWNO ":" 3 "," Fremark ":" "," Fdeptname ":" Internal Medicine "," Fplvcode ":", "Fdeptcode": "},{", "Fstate": "1", " Frcode ":" 410000 "," FZJM ":" WK "," ROWNO ":" 4 "," Fremark ":" "," Fdeptname ":" Surgery "," Fplvcode ":" "," Fdeptcode ":" 04 "},{" Fstate ":" 1 "," Frcode ":" 410000 "," FZJM ":" FCK "," ROWNO ":" 5 "," Fremark ":" "," Fdeptname ":" Obstetrics and Gynecology "," Fplvcode ":", "Fdeptcode ":"}]; 
// take an array element var jsonobj = eval (jsonstr);  for (var i = 0; I <jsonObj.length; i++) {    console.log (Jsonobj[i]. FZJM);}

Summary:

If it is a JSON format string, the value is evaluated with eval (' (' +json format string + ') ');
In the case of JSON format data, the value is evaluated in the form of eval (JSON format);

Java-map format

{data=[{term= Phase I, wangwu=199, lisi=229, zhaoliu=233, sanqi=234, zhangsan=233},{term= Phase II, wangwu=156, LISI=186, ZHAOLIU =179, sanqi=206, zhangsan=234}, {term= phase III, wangwu=133, lisi=161, zhaoliu=246, sanqi=185, zhangsan=240}, {term= Fourth, wangwu=194, lisi=126, zhaoliu=190, sanqi=207, zhangsan=229},{term= Fifth, wangwu=149, lisi=166, ZHAOLIU=209, SANQI=174, zhangsan=197}], code=0, expmsg=, msg= operation succeeded}
/**/var row = ' ${model.data} ';

Row represents the

[{term= Phase I, wangwu=199, lisi=229, zhaoliu=233, sanqi=234, zhangsan=233}, {term= II, wangwu=156, lisi=186, ZHAOLIU=179, sanqi=206, zhangsan=234}, {term= phase III, wangwu=133, lisi=161, zhaoliu=246, sanqi=185, zhangsan=240}, {term= fourth, WANGWU=194 , lisi=126, zhaoliu=190, sanqi=207, zhangsan=229}, {term= fifth, wangwu=149, lisi=166, zhaoliu=209, sanqi=174, ZHANGSAN=197 }]
 /*  * cannot use for loop * for (var i =0; i<row.length ; i++) {* Xaxisvalues.push (' ${row[i]. term} '); *}  */  only use the C tag of the JSTL tag library to iterate  <c:        ForEach var  = "Row" items= "${model.data}" > ' ${row.    term} ' 
/** *//var test = ' <%=request.getattribute ("model")%> '; // {data=[{term= Phase II, wangwu=156, lisi=186, zhaoliu=179, sanqi=206, zhangsan=234}, {term= III, wangwu=133, LISI=161, zhaoliu=246, sanqi=185, zhangsan=240}, {term= fifth, wangwu=149, lisi=166, zhaoliu=209, sanqi=174, ZHANGSAN=197}, {TERM= First phase, wangwu=199, lisi=229, zhaoliu=233, sanqi=234, zhangsan=233}, {term= Fourth, wangwu=194, lisi=126, zhaoliu=190, SANQI= 207, zhangsan=229}], code=0, expmsg=, msg= operation succeeded}

Second, the conversion between data formats

In JS, JSON-formatted strings and object types can be converted to each other
A.json format string into an array of type Object

var jsonobj = eval ("(" +row+ ")"); Console.log (jsonobj); // "[Object Object],[object object],[object object],[object Object],[object Object]"

B.object types into JSON strings

var str = json.stringify (jsonobj); Console.log (str); // "[{" term ":" First period "," Wangwu ": 199," LISI ": 229," Zhaoliu ": 233," Sanqi ": 234," Zhangsan ": 233},{" term ":" \t\t Two "," Wangwu ": 156," LISI ": 186," Zhaoliu ": 179," Sanqi ": 206," Zhangsan ": 234},{" term ":" Third \t\t period "," Wangwu ": 133," LISI ": 161," Zhaoliu ": 246," Sanqi ": 185," Zhangsan ": 240},{" term ":" Fourth \t\t\t period "," Wangwu ": 194," LISI ": 126," Zhaoliu ":," Sanqi ": 207 , "Zhangsan": 229},{"term": "Fifth \t\t\t", "Wangwu": 149, "LISI ": 166, "Zhaoliu": 209, "Sanqi": 174, "Zhangsan": 197}] "

Data Format Rollup-js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.