Is there a better way to parse this data, especially considering it might have extra JavaScript code around it?
My Sample Data:
Strdata = <script language=”JavaScript” src=”WEB-CORE/scripts/sapphirersaencrypt.js”></script>
<script language=”JavaScript”>var rsa = new RSAKey();rsa.setPublic(‘…’);</script>
<script type=”text/javascript” src=”WEB-CORE/scripts/json.js”></script>
<script type=”text/javascript”>…some more scripts…</script>
<!– The JSON data in the JavaScript code –>
“NCR1”:[{“unit”:”DCT”,”year”:2021,”sum”:0},…]
“NCR2”:{“color”:[“#A40000″,”#A40000″,”#DA0000″,”#F20000”],…}
My Expect Result is
{
"NCR1":[
{
"unit":"DCT",
"year":2021,
"sum":0
},
{
"unit":"DCT",
"year":2022,
"sum":0
},
{
"unit":"DCT",
"year":2023,
"sum":0
},
{
"unit":"DCT",
"year":2024,
"sum":3
},
{
"unit":"Final product",
"year":2021,
"sum":0
},
{
"unit":"Final product",
"year":2022,
"sum":0
},
{
"unit":"Final product",
"year":2023,
"sum":0
},
{
"unit":"Final product",
"year":2024,
"sum":1
}
],
"NCR2":{
"color":[
"#A40000",
"#A40000",
"#DA0000",
"#F20000",
"#FF6969",
"#FF9797",
"#FFBDBD",
"#FFD5D5",
"#FEBB00",
"#FEBB00",
"#FFD966",
"#FFEDB3",
"#FF00FF",
"#FF00FF",
"#FF66FF",
"#FF99FF",
"#70AD47",
"#70AD47",
"#A9D08E",
"#C6E0B4",
"#C6E0B4",
"#305496",
"#305496",
"#2F75B5",
"#5597D3",
"#88B6E0",
"#B4C6E7",
"#D9E1F2"
],
"objSeries":[
{
"grp":"Properties",
"data":[
null,
null,
null,
null
],
"name":"Properties"
},
{
"data":[
0,
0,
0,
1
],
"name":"Flow"
},
{
"data":[
0,
0,
0,
0
],
"name":"Mechanical"
},
{
"data":[
0,
0,
0,
1
],
"name":"Chemical & Residual"
},
{
"data":[
0,
0,
0,
0
],
"name":"Addtive"
},
{
"data":[
0,
0,
0,
0
],
"name":"Heat stability"
},
{
"data":[
0,
0,
0,
0
],
"name":"Special F-Emission"
},
{
"data":[
0,
0,
0,
0
],
"name":"Others"
},
{
"grp":"Color & App",
"data":[
null,
null,
null,
null
],
"name":"Color & App"
},
{
"data":[
0,
0,
0,
0
],
"name":"Color"
},
{
"data":[
0,
0,
0,
0
],
"name":"Transparency"
},
{
"data":[
0,
0,
0,
0
],
"name":"Appearance"
},
{
"grp":"Contaminate",
"data":[
null,
null,
null,
null
],
"name":"Contaminate"
},
{
"data":[
0,
0,
0,
0
],
"name":"Contamination"
},
{
"data":[
0,
0,
0,
0
],
"name":"Burned Material"
},
{
"data":[
0,
0,
0,
0
],
"name":"Foreign Material"
},
{
"grp":"Others",
"data":[
null,
null,
null,
null
],
"name":"Others"
},
{
"data":[
0,
0,
0,
0
],
"name":"Packaging"
},
{
"data":[
0,
0,
0,
0
],
"name":"Trial product"
},
{
"data":[
0,
0,
0,
0
],
"name":"Suspect product"
},
{
"data":[
0,
0,
0,
0
],
"name":"Others"
},
{
"grp":"Raw Mat",
"data":[
null,
null,
null,
null
],
"name":"Raw Mat"
},
{
"data":[
0,
0,
0,
0
],
"name":"Appearance"
},
{
"data":[
0,
0,
0,
0
],
"name":"Contamination"
},
{
"data":[
0,
0,
0,
0
],
"name":"Properties"
},
{
"data":[
0,
0,
0,
0
],
"name":"Over Shelflife"
},
{
"data":[
0,
0,
0,
0
],
"name":"Packaging"
},
{
"data":[
0,
0,
0,
0
],
"name":"Other"
}
],
"categories":[
2021,
2022,
2023,
2024
]
},
"NCR3":{
"color":[
"#DA0000",
"#DA0000",
"#FF6969",
"#2F75B5",
"#2F75B5",
"#5597D3",
"#88B6E0",
"#B4C6E7",
"#FEBB00",
"#FEBB00",
"#FFD966",
"#FFEDB3",
"#FFEDB3",
"#FF00FF",
"#FF00FF",
"#FF66FF",
"#FF99FF",
"#70AD47",
"#70AD47",
"#A9D08E",
"#C6E0B4"
],
"objSeries":[
{
"grp":"Man",
"data":[
null,
null,
null,
null
],
"name":"Man"
},
{
"data":[
0,
0,
0,
0
],
"name":"Mis-additive/recipe"
},
{
"data":[
0,
0,
0,
1
],
"name":"Mis-operation/condition"
},
{
"grp":"Machine",
"data":[
null,
null,
null,
null
],
"name":"Machine"
},
{
"data":[
0,
0,
0,
0
],
"name":"Polymerization Facility"
},
{
"data":[
0,
0,
0,
1
],
"name":"Extrusion & Pelletizing Facility"
},
{
"data":[
0,
0,
0,
0
],
"name":"Packing Facility"
},
{
"data":[
0,
0,
0,
0
],
"name":"Process instrument / equipment trouble"
},
{
"grp":"Method",
"data":[
null,
null,
null,
null
],
"name":"Method"
},
{
"data":[
0,
0,
0,
0
],
"name":"RM preparing method"
},
{
"data":[
0,
0,
0,
0
],
"name":"Process Condition / operation & environment control"
},
{
"data":[
0,
0,
0,
0
],
"name":"Inspection method"
},
{
"data":[
0,
0,
0,
0
],
"name":"Recipe or Technology"
},
{
"grp":"Material",
"data":[
null,
null,
null,
null
],
"name":"Material"
},
{
"data":[
0,
0,
0,
3
],
"name":"RM quality"
},
{
"data":[
0,
0,
0,
0
],
"name":"Base resin"
},
{
"data":[
0,
0,
0,
0
],
"name":"Packaging"
},
{
"grp":"Other",
"data":[
null,
null,
null,
null
],
"name":"Other"
},
{
"data":[
0,
0,
0,
0
],
"name":"Storage & delivery"
},
{
"data":[
0,
0,
0,
0
],
"name":"Over shelf life / Dead stock"
},
{
"data":[
0,
0,
0,
0
],
"name":"Other"
}
],
"categories":[
2021,
2022,
2023,
2024
]
},
"NCR4":{
"color":[
"#70AD47",
"#A9D08E",
"#FFFF99",
"#F4B084",
"#ED49F1",
"#FFC000",
"#FF6969",
"#7030A0",
"#EA0000",
"#AEAAAA"
],
"objSeries":[
{
"data":[
0,
0,
0,
3
],
"name":"Special accept as normal"
},
{
"data":[
0,
0,
0,
0
],
"name":"Special accept with condition"
},
{
"data":[
0,
0,
0,
0
],
"name":"Grade change as specified"
},
{
"data":[
0,
0,
0,
0
],
"name":"Rework"
},
{
"data":[
0,
0,
0,
0
],
"name":"Multiple handling as specified"
},
{
"data":[
0,
0,
0,
0
],
"name":"Off spec for sale as wide spec"
},
{
"data":[
0,
0,
0,
0
],
"name":"Off spec for recycle"
},
{
"data":[
0,
0,
0,
0
],
"name":"Reject"
},
{
"data":[
0,
0,
0,
0
],
"name":"Waste"
},
{
"data":[
0,
0,
0,
0
],
"name":"Other"
}
],
"categories":[
2021,
2022,
2023,
2024
]
}
}