Dear Amibroker Team/Friends,
Please help me
How Parse JSON with dynamic key
it is important specially for nested json data or big data
Please find below code as example
Thanks
P.K. Behera
EnableScript("jscript");
<%
function _Parse( json_string )
{
return JSON.parse( json_string );
}
%>
function ParseJSON( json_string )
{
script = GetScriptObject();
return script._Parse( json_string );
}
jsonData={
"stockList": {
"Stock0": "HDFCBANK,RELIANCE,LT,INFY,ADANIENT,SBIN,ADANIPORTS,ICICIBANK,TCS,BHARTIARTL,MARUTI,KOTAKBANK,ONGC,APOLLOHOSP,IDEA,ITC,BAJFINANCE",
"Stock1": "TATASTEEL,AXISBANK,NTPC,TATAMOTORS,M&M,RECLTD,HINDUNILVR,HAL,BEL,PFC,COALINDIA,TITAN,DLF,HEROMOTOCO,BPCL,CANBK,HINDALCO",
"Stock2": "VEDL,BHEL,WIPRO,TATAPOWER,INDUSINDBK,IRCTC,SUNPHARMA,HCLTECH,GAIL,IDFCFIRSTB,BANKBARODA,ASIANPAINT,HDFCLIFE,ASHOKLEY,AMBUJACEM,BATAINDIA,MOTHERSON",
"Stock3": "TECHM,DIXON,CUMMINSIND,EXIDEIND,NMDC,BERGEPAINT,BAJAJFINSV,UPL,ULTRACEMCO,HINDPETRO,PNB,MUTHOOTFIN,VOLTAS,AUBANK,IGL,SAIL,GMRINFRA",
"Stock4": "IPCALAB,INDIGO,TVSMOTOR,JINDALSTEL,TATACHEM,IOC,ABFRL,JUBLFOOD,POWERGRID,CIPLA,ACC,GRASIM,JSWSTEEL,DRREDDY,CHOLAFIN,INDUSTOWER,TATACONSUM",
"Stock5": "TRENT,DIVISLAB,LTTS,NATIONALUM,AUROPHARMA,LICHSGFIN,BANDHANBNK,LTIM,BAJAJ-AUTO,SBILIFE,NESTLEIND,SBICARD,GUJGASLTD,PERSISTENT,FEDERALBNK,INDHOTEL,POLYCAB",
"Stock6": "SHRIRAMFIN,HINDCOPPER,HDFCAMC,BIOCON,CONCOR,MGL,HAVELLS,PEL,IEX,PETRONET,COFORGE,DABUR,RBLBANK,ZEEL,MCX,APOLLOTYRE,BHARATFORG",
"Stock7": "CUB,ALKEM,DEEPAKNTR,LUPIN,EICHERMOT,BSOFT,M&MFIN,OBEROIRLTY,MANAPPURAM,AARTIIND,CHAMBLFERT,BRITANNIA,MARICO,PVRINOX,PAGEIND,GLENMARK,LAURUSLABS",
"Stock8": "ZYDUSLIFE,ASTRAL,ABCAPITAL,UBL,ABB,SIEMENS,GODREJPROP,TATACOMM,GNFC,BALKRISIND,BOSCHLTD,SRF,LTF,MPHASIS,PIDILITIND,NAUKRI,MCDOWELL-N",
"Stock9": "IDFC,GRANULES,CANFINHOME,DALBHARAT,SUNTV,COROMANDEL,BALRAMCHIN,INDIACEM,GODREJCP,COLPAL,ICICIPRULI,ESCORTS,INDIAMART,PIIND,RAMCOCEM,NAVINFLUOR,CROMPTON",
"Stock10": "MFSL,SYNGENE,ICICIGI,SHREECEM,OFSS,MRF,TORNTPHARM,METROPOLIS,ATUL,LALPATHLAB,JKCEMENT,ABBOTINDIA"
}
}
ListNumber=Param("ListNumber",0,0,100,1);
list=ParseJSON( jsonData );
list=list.stockList;
Stocklist=list.Stock0;////Work fine
Stocklist=list.Stock+ListNumber; //Got Error but i want to use dynamic key