CRC-16-IBM implementation (JS) not working - javascript

Background
I receive a buffer of bytes that has a CRC check at the end. According to the manual, this is the CRC-16-IBM algorithm with the polynomial 0xA001 ( reversed as seen in Wikipedia ).
Research
To implement this I translated code from several SO questions from Java to C# into JS but nothing seems to work and I have no idea why.
Code
Here is the implementation I am currently dealing with:
const crc16ibm = buffer => {
const table = [
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
];
let crc = 0x0000;
for( const byte of buffer ){
crc = crc >>> 8 ^ table[ ( crc ^ byte ) & 0xff ];
}
return crc;
};
module.exports = crc16ibm;
Here is a test that is supposed to work:
const hexStr = Buffer.from( "000000000000001C0D01050000001056E924222347455420444154414F524445520D0A01", "hex");
const expectedCrc = 0x00004990;
assert( crc16ibm( hexStr ), expectedCrc ); //NOPE!
What is wrong?
I have quite literally tried everything, but either the examples I am using to test my code are wrong, or I have no idea on what's going on. At this point I weight both equally.
Is the problem with the lookup table?
The manual provides a graphic with an image of a ( quite inefficient ) possible way to implement this, via repeated for loops instead of using a table:
But I would much rather use a table and find out what is actually wrong in my current algorithm...

There's nothing wrong with your table or code to compute the CRC described in the flow chart. There must be something wrong with your test vector.

I did this and it worked
const crc16ibm = buffer => {
const table = [
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
];
let crc = 0x0000;
for( const byte of buffer ){
crc = crc >>> 8 ^ table[ ( crc ^ byte ) & 0xff ];
}
return crc;
};
module.exports.crc16ibm = crc16ibm;
This is how yo can try it
/*
const crc16ibm= require("./crc16ibm").crc16ibm; console.log((crc16ibm(Buffer.from('0C010500000007676574696E666F01','hex'))).toString(16));
*/

Related

How do I improve my index array without typing it all out

SLink = [...Array(100).keys()].map(i => `SotiLink[${i}]`)
MCLink = [...Array(100).keys()].map(i => `<MCLink${i}>`)
SotiLink = SLink + MCLink;
console.log(SotiLink)
As a newbie to js I have been trying to improve the current situation, which is as follows:
SotiLink[0] = "<MCLink0>";
SotiLink[1] = "<MCLink1>";
SotiLink[2] = "<MCLink2>";
Now this works fine, it gets the job done.
But I thought something like this would be better:
SotiLink[...Array(100).keys()] = "<MCLink0>", "<MCLink1>", "<MCLink2>", "<MCLink3>", "<MCLink4>", "<MCLink5>", "<MCLink6>", "<MCLink7>", "<MCLink8>", "<MCLink9>", "<MCLink10>", "<MCLink11>", "<MCLink12>", "<MCLink13>", "<MCLink14>", "<MCLink15>", "<MCLink16>", "<MCLink17>", "<MCLink18>", "<MCLink19>", "<MCLink20>", "<MCLink21>", "<MCLink22>", "<MCLink23>", "<MCLink24>", "<MCLink25>", "<MCLink26>", "<MCLink27>", "<MCLink28>", "<MCLink29>", "<MCLink30>", "<MCLink31>", "<MCLink32>", "<MCLink33>", "<MCLink34>", "<MCLink35>", "<MCLink36>", "<MCLink37>", "<MCLink38>", "<MCLink39>", "<MCLink40>", "<MCLink41>", "<MCLink42>", "<MCLink43>", "<MCLink44>", "<MCLink45>", "<MCLink46>", "<MCLink47>", "<MCLink48>", "<MCLink49>", "<MCLink50>", "<MCLink51>", "<MCLink52>", "<MCLink53>", "<MCLink54>", "<MCLink55>", "<MCLink56>", "<MCLink57>", "<MCLink58>", "<MCLink59>", "<MCLink60>", "<MCLink61>", "<MCLink62>", "<MCLink63>", "<MCLink64>", "<MCLink65>", "<MCLink66>", "<MCLink67>", "<MCLink68>", "<MCLink69>", "<MCLink70>", "<MCLink71>", "<MCLink72>", "<MCLink73>", "<MCLink74>", "<MCLink75>", "<MCLink76>", "<MCLink77>", "<MCLink78>", "<MCLink79>", "<MCLink80>", "<MCLink81>", "<MCLink82>", "<MCLink83>", "<MCLink84>", "<MCLink85>", "<MCLink86>", "<MCLink87>", "<MCLink88>", "<MCLink89>", "<MCLink90>", "<MCLink91>", "<MCLink92>", "<MCLink93>", "<MCLink94>", "<MCLink95>", "<MCLink96>", "<MCLink97>", "<MCLink98>", "<MCLink99>";
Where instead of numbering the Sotilink 0-100 it would generate all the numbers.
Ideally I would like the same for MCLink, but so far I had no succes.
I tried to recreate it somewhat in the snippet but I had no succes there either...
Perhaps someone can point me in the correct direction?
Almost there ;)
SotiLink = [...Array(100).keys()].map(i => `<MCLink${i}>`)
console.log(SotiLink)
As a side note, I'm wondering how did you create that snippet in your question. Did you really type all 100 strings? :o

Unable to decode QRCode with qrcode-reader NodeJS

I am using the following code to decode qrcodes using the qrcode-reader library. I am able to decode simple qrcodes that I have generated from various sites. However, I am unable to decode more complex qrcodes like the attached and receive "Couldn't find enough alignment patterns". I am able to decode this qrcode with a free Android app. What do I need to do to decode this qrcode?
it.only('test QrCode', async () => {
await Promise.resolve();
const buffer = fs.readFileSync(`${__dirname }/test.png`);
const image = await Jimp.read(buffer);
const qrcode = new QrCode();
qrcode.callback = function(err, value) {
if (err) {
console.error(`err: ${err}`);
} else {
console.log(`value: ${JSON.stringify(value)}`);
}
};
qrcode.decode(image.bitmap);
});
Edit:
The contents of the qrcode is in a compressed format using jszip. This is what I was able to decode using a random Android qrcode reader app from the play store
PK
ŠiÞRØ)E è Ù certificate.json Tioê: ý+(Ÿ f Jùr „²ïa zª&‰ À¦Ž
Uÿû ·´Rß"E‘<s<Ë™3~×þð8“äMj•?µ ”‡¸òðp< óG+ÏEø`êFùÁ Ä'LRØÅ ©¡e? ?R– yš§ì;
< 2 ”3u㯬&O ¢r̉ wGìO<F ΃a0¿ßûâÆë4Ž "´ÊÏ©µ+ ˜Gê 1 fꦑÓK9KŸê…Š®ã—×u} HÆÙT ‹ "T –"!è¸7à$nD<ääýV·6""æLåññäS¿rËžP h Àß ˆŠi ð³,«€PA‚¶B h*©Ä°W¡j 8A¦O¥ 4†„ù—Æú°SE#x)ÿñ‚W<ÀŽÊ šÚ̧ * ß $ŽUq± „ÈêoƒfèFÎÐÍl¦ ,„]¦ o¨8‚ ·¾AMÄ:™yfÂ/>Ÿ¢—ª~5 ˜ O$çÌ‚ÄR‘rÍÞOö.Ð{ö ±¶KÙ o®Ýܼ6O˜ —ª h=ðXÂÎæ¾j­€c( ´ ¬FRŠ„{J ïWb œîULDM9 ÄwÁÛÎÄîŸÐ¿Ô XÀÿ ò©Ç»â”Î\ ÞFµUÃI–kKDÞÒ£ÑæsxCË X €' q™œ=œ „½"À¿ËO/Y:ZH ”hJ B^}º ¿¯¾ Ênwõ o>ŸÇ*’Z7É‘¾:žã›!½,‘Jþþ[U ç ¢ŒCY¸Ñ [¬ ^•ó ©ÖìLŸøÔCeØ(t¼ÿïj2­l¦‹a÷ 5ÁO*ú®ž QÀD$ ‡'rs—ϧã uA ÿ°ýŸúAå|à êÁø² “ b Šz´®ûŒÓð¿¿ †U1ÌŠyy ®4z—á÷‰Üðûnã®i·$£D ®³€8&â 8«EGE 9u6nÓ£CÚ ÏÎmc#Ûq{ß6 v»´Þ7bÏœáyp‚å˜ w1]E+½½3žòù™ÿÊW½·5xƒÂs¹S{êO·ërgÛë.K,4ç ólñº<V“`î%ro "k±~zõº¹z=b²XöŸÓ—£áÛ, §¡ûÂÚõ {® ]½Ô,Ÿ[ËY¡ TWæK# 3½t '6 .»U$·®{¸Fnk;
å\‹wžÜ·×u,JƒEd aµ1Z yîÐêy;KzFÐhºQ
|v
çi59®h¹Yï 7S§ž¶‹§Õ㢠¥ÕÜ3G‹ÒÒZøµpäå^C äc:éMKåç¨4›öÂck¥—É&‰ AIÚ³úÀ 4ƒiÐnÉ Oìí0,ZüÅ}z,ÏíÖÉy$‹åv<öÃãºÉ ¦;?E sd4'
; ‡NÍq¬Ð¬ ’¥áô"˜ 'c”ÈßPK
ŠiÞRØ)E è Ù certificate.jsonPK >

I can't decode a url encoded in unknow format on an ASP site

I'm scraping through a website and this website has a form the form is in the Arabic language so it's encoding everything (inputs) to let the form get work properly
MY problem is I'm scraping using JS and decodeUri/decodeUriComponent not working with the encoding output string that coming from the site.
even the browser says unable to decode value in console dev
the link example that I need to get it decoded:
http://app2.helwan.edu.eg/HelwanNat/Education/TermAlist.asp?x_level=2020%2D2019&z_level=LIKE&x_dep=%C7%E1%DA%E1%E6%E3+%2D%CA%DA%E1%ED%E3+%C7%D3%C7%D3%EC&z_dep=LIKE&x_st_name=%E3%CD%E3%CF&z_st_name=LIKE
This appears to be a windows-1256 encoding.
You can decode it in js like so:
function decode(string) {
var array = [...string.matchAll(/%(.{2})/g)].map((groups) => parseInt(groups[1], 16));
var decoder = new TextDecoder('windows-1256');
return decoder.decode(Uint8Array.from(array).buffer);
}
console.log(decode('%E3%CD%E3%CF'));
console.log('%C7%E1%DA%E1%E6%E3+%2D%CA%DA%E1%ED%E3+%C7%D3%C7%D3%EC'.split('+').map(decode));
Since TextEncoder() can only encode utf-8 strings, you will have to make a conversion table for windows-1256:
windows_1256 = [
'\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', '\u0008', '\u0009', '\u000A', '\u000B', '\u000C', '\u000D', '\u000E', '\u000F',
'\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', '\u0018', '\u0019', '\u001A', '\u001B', '\u001C', '\u001D', '\u001E', '\u001F',
'\u0020', '\u0021', '\u0022', '\u0023', '\u0024', '\u0025', '\u0026', '\u0027', '\u0028', '\u0029', '\u002A', '\u002B', '\u002C', '\u002D', '\u002E', '\u002F',
'\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039', '\u003A', '\u003B', '\u003C', '\u003D', '\u003E', '\u003F',
'\u0040', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045', '\u0046', '\u0047', '\u0048', '\u0049', '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F',
'\u0050', '\u0051', '\u0052', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057', '\u0058', '\u0059', '\u005A', '\u005B', '\u005C', '\u005D', '\u005E', '\u005F',
'\u0060', '\u0061', '\u0062', '\u0063', '\u0064', '\u0065', '\u0066', '\u0067', '\u0068', '\u0069', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F',
'\u0070', '\u0071', '\u0072', '\u0073', '\u0074', '\u0075', '\u0076', '\u0077', '\u0078', '\u0079', '\u007A', '\u007B', '\u007C', '\u007D', '\u007E', '\u007F',
'\u20AC', '\u067E', '\u201A', '\u0192', '\u201E', '\u2026', '\u2020', '\u2021', '\u02C6', '\u2030', '\u0679', '\u2039', '\u0152', '\u0686', '\u0698', '\u0688',
'\u06AF', '\u2018', '\u2019', '\u201C', '\u201D', '\u2022', '\u2013', '\u2014', '\u06A9', '\u2122', '\u0691', '\u203A', '\u0153', '\u200C', '\u200D', '\u06BA',
'\u00A0', '\u060C', '\u00A2', '\u00A3', '\u00A4', '\u00A5', '\u00A6', '\u00A7', '\u00A8', '\u00A9', '\u06BE', '\u00AB', '\u00AC', '\u00AD', '\u00AE', '\u00AF',
'\u00B0', '\u00B1', '\u00B2', '\u00B3', '\u00B4', '\u00B5', '\u00B6', '\u00B7', '\u00B8', '\u00B9', '\u061B', '\u00BB', '\u00BC', '\u00BD', '\u00BE', '\u061F',
'\u06C1', '\u0621', '\u0622', '\u0623', '\u0624', '\u0625', '\u0626', '\u0627', '\u0628', '\u0629', '\u062A', '\u062B', '\u062C', '\u062D', '\u062E', '\u062F',
'\u0630', '\u0631', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u00D7', '\u0637', '\u0638', '\u0639', '\u063A', '\u0640', '\u0641', '\u0642', '\u0643',
'\u00E0', '\u0644', '\u00E2', '\u0645', '\u0646', '\u0647', '\u0648', '\u00E7', '\u00E8', '\u00E9', '\u00EA', '\u00EB', '\u0649', '\u064A', '\u00EE', '\u00EF',
'\u064B', '\u064C', '\u064D', '\u064E', '\u00F4', '\u064F', '\u0650', '\u00F7', '\u0651', '\u00F9', '\u0652', '\u00FB', '\u00FC', '\u200E', '\u200F', '\u06D2'
];
function encode(string){
return [...string].map(c => `%${windows_1256.indexOf(c).toString(16).toUpperCase()}`).join('');
}
console.log(encode('محمد'));
console.log(['العلوم', "-تعليم", "اساسى"].map(encode).join('+'));

Javascript: Array does not work when it is a little long

I want to replace Chinese characters to unicode and the unicode to pinyin (pronunciations of those characters) so that I can make Hansi (Persianized pronunciations). I do this using arrays. I don't have any problem with this:
// here i got the chinese character and replaced it with unicode
var chini = document.getElementById("ch1").value.charCodeAt(0);
var chiniuni= chini.toString(16);
var mapUni1 = {
"3007":"ling2", "4e00":"yi1", "4e01":"ding1", "4e02":"kao3", "4e03":"qi1", "4e04":"shang4---shang3", "4e05":"xia4", "4e06":"---", "4e07":"wan4---mo4", "4e08":"zhang4", "4e09":"san1", "4e0a":"shang4---shang3", "4e0b":"xia4", "4e0c":"ji1", "4e0d":"bu4", "4e0e":"yu3---yu4", "4e0f":"mian3", "4e10":"gai4","4e11":"chou3", "4e12":"chou3", "4e13":"zhuan1", "4e14":"qie3---ju1", "4e15":"pi1", "4e16":"shi4", "4e17":"shi4", "4e18":"qiu1", "4e19":"bing3", "4e1a":"ye4", "4e1b":"cong2", "4e1c":"dong1",
};
var roo = new RegExp(Object.keys(mapUni1).join("|"),"gi");
pinyin = chiniuni.toLowerCase().replace(roo, function(matched){
return mapUni1[matched];
});
document.getElementById("bbb").innerHTML = pinyin
check it here: https://jsfiddle.net/6j7k5dqw/
But since there are a lot of Chinese characters (21000 in my work), the array must be a little long, and I read that it can be much much longer. But in my case, when I put a little more in the array, the code does not work at all:
var chini = document.getElementById("ch1").value.charCodeAt(0);
var chiniuni= chini.toString(16);
var mapUni1 = {
"3007":"ling2", "4e00":"yi1", "4e01":"ding1", "4e02":"kao3", "4e03":"qi1", "4e04":"shang4---shang3", "4e05":"xia4", "4e06":"---", "4e07":"wan4---mo4", "4e08":"zhang4", "4e09":"san1", "4e0a":"shang4---shang3", "4e0b":"xia4", "4e0c":"ji1", "4e0d":"bu4", "4e0e":"yu3---yu4", "4e0f":"mian3", "4e10":"gai4","4e11":"chou3", "4e12":"chou3", "4e13":"zhuan1", "4e14":"qie3---ju1", "4e15":"pi1", "4e16":"shi4", "4e17":"shi4", "4e18":"qiu1", "4e19":"bing3", "4e1a":"ye4", "4e1b":"cong2", "4e1c":"dong1", "4e1d":"si1", "4e1e":"cheng2", "4e1f":"diu1", "4e20":"qiu1", "4e21":"liang3", "4e22":"diu1", "4e23":"you3", "4e24":"liang3", "4e25":"yan2", "4e26":"bing4", "4e27":"sang1---sang4", "4e28":"shu4", "4e29":"jiu1", "4e2a":"ge4", "4e2b":"ya1", "4e2c":"qiang2---pan2", "4e2d":"zhong1---zhong4", "4e2e":"ji3", "4e2f":"jie4", "4e30":"feng1", "4e31":"guan4", "4e32":"chuan4", "4e33":"chan3", "4e34":"lin2", "4e35":"zhuo1", "4e36":"zhu3", "4e37":"---", "4e38":"wan2",
"4e39":"dan1", "4e3a":"wei4---wei2", "4e3b":"zhu3", "4e3c":"jing3---dan3", "4e3d":"li4---li2", "4e3e":"ju3", "4e3f":"pie3", "4e40":"fu2", "4e41":"yi2", "4e42":"yi4---ai4", "4e43":"nai3", "4e44":"---", "4e45":"jiu3", "4e46":"jiu3", "4e47":"tuo1", "4e48":"yao1---mo2", "4e49":"yi4", "4e4a":"---", "4e4b":"zhi1", "4e4c":"wu1---wu4", "4e4d":"zha4", "4e4e":"hu1", "4e4f":"fa2", "4e50":"le4---yue4", "4e51":"zhong4", "4e52":"ping1", "4e53":"pang1", "4e54":"qiao2", "4e55":"hu3---hu4", "4e56":"guai1", "4e57":"cheng2---sheng4", "4e58":"cheng2---sheng4", "4e59":"yi3", "4e5a":"yin3", "4e5b":"---", "4e5c":"mie1---nie4", "4e5d":"jiu3", "4e5e":"qi3", "4e5f":"ye3", "4e60":"xi2", "4e61":"xiang1", "4e62":"gai4", "4e63":"diu1", "4e64":"---", "4e65":"---", "4e66":"shu1", "4e67":"---", "4e68":"shi3", "4e69":"ji1", "4e6a":"nang1", "4e6b":"jia1", "4e6c":"---", "4e6d":"shi2", "4e6e":"---", "4e6f":"---", "4e70":"mai3", "4e71":"luan4", "4e72":"---", "4e73":"ru3", "4e74":"xi3", "4e75":"yan3", "4e76":"fu3", "4e77":"sha1", "4e78":"na3", "4e79":"gan1---qian2", "4e7a":"---", "4e7b":"---", "4e7c":"---", "4e7d":"---", "4e7e":"gan1---qian2", "4e7f":"zhi4", "4e80":"gui1---jun1---qiu1", "4e81":"gan1", "4e82":"luan4", "4e83":"lin3", "4e84":"yi4", "4e85":"jue2", "4e86":"liao3---le5", "4e87":"---", "4e88":"yu2---yu3", "4e89":"zheng1", "4e8a":"shi4", "4e8b":"shi4", "4e8c":"er4", "4e8d":"chu4", "4e8e":"yu2", "4e8f":"kui1", "4e90":"yu2", "4e91":"yun2", "4e92":"hu4", "4e93":"qi2", "4e94":"wu3", "4e95":"jing3", "4e96":"si4",
"4e97":"sui4", "4e98":"gen4", "4e99":"gen4---geng4", "4e9a":"ya4", "4e9b":"xie1", "4e9c":"ya4", "4e9d":"qi2", "4e9e":"ya4---ya3", "4e9f":"ji2---qi4", "4ea0":"tou2", "4ea1":"wang2---wu2", "4ea2":"kang4", "4ea3":"ta4", "4ea4":"jiao1", "4ea5":"hai4", "4ea6":"yi4", "4ea7":"chan3", "4ea8":"heng1", "4ea9":"mu3", "4eaa":"---", "4eab":"xiang3", "4eac":"jing1", "4ead":"ting2", "4eae":"liang4", "4eaf":"heng1", "4eb0":"jing1", "4eb1":"ye4", "4eb2":"qin1---qing4", "4eb3":"bo4", "4eb4":"you4", "4eb5":"xie4", "4eb6":"dan3", "4eb7":"lian2", "4eb8":"duo3", "4eb9":"wei3---wei4", "4eba":"ren2", "4ebb":"ren2", "4ebc":"ji2", "4ebd":"---", "4ebe":"wang2", "4ebf":"yi4", "4ec0":"shi2---shen2", "4ec1":"ren2", "4ec2":"le4", "4ec3":"ding1", "4ec4":"ze4", "4ec5":"jin3---jin4", "4ec6":"pu1---pu2", "4ec7":"chou2---qiu2", "4ec8":"ba1", "4ec9":"zhang3", "4eca":"jin1", "4ecb":"jie4", "4ecc":"bing1", "4ecd":"reng2", "4ece":"cong2", "4ecf":"fo2---fu2", "4ed0":"san3", "4ed1":"lun2", "4ed2":"---", "4ed3":"cang1", "4ed4":"zi3", "4ed5":"shi4", "4ed6":"ta1", "4ed7":"zhang4", "4ed8":"fu4", "4ed9":"xian1", "4eda":"xian1", "4edb":"cha4", "4edc":"hong2", "4edd":"tong2", "4ede":"ren4", "4edf":"qian1", "4ee0":"gan3", "4ee1":"yi4---ge1", "4ee2":"di2", "4ee3":"dai4", "4ee4":"ling4---ling2---ling3", "4ee5":"yi3", "4ee6":"chao4", "4ee7":"chang2", "4ee8":"sa1", "4ee9":"shang4", "4eea":"yi2", "4eeb":"mu4",
"4eec":"men5---men2", "4eed":"ren4", "4eee":"jia3---jia4", "4eef":"chao4", "4ef0":"yang3", "4ef1":"qian2", "4ef2":"zhong4", "4ef3":"pi3", "4ef4":"wan4", "4ef5":"wu3", "4ef6":"jian4", "4ef7":"jia4", "4ef8":"yao3", "4ef9":"feng1", "4efa":"cang1", "4efb":"ren4---ren2", "4efc":"wang2", "4efd":"fen4", "4efe":"di1", "4eff":"fang3", "4f00":"zhong1", "4f01":"qi3---qi4", "4f02":"pei4", "4f03":"yu2", "4f04":"diao4", "4f05":"dun4", "4f06":"wen4", "4f07":"yi4", "4f08":"xin3", "4f09":"kang4", "4f0a":"yi1", "4f0b":"ji2", "4f0c":"ai4", "4f0d":"wu3", "4f0e":"ji4", "4f0f":"fu2", "4f10":"fa2---fa1", "4f11":"xiu1", "4f12":"jin4", "4f13":"bei1", "4f14":"chen2", "4f15":"fu1", "4f16":"tang3", "4f17":"zhong4", "4f18":"you1", "4f19":"huo3", "4f1a":"hui4---kuai4", "4f1b":"yu3", "4f1c":"cui4---zu2", "4f1d":"yun2", "4f1e":"san3", "4f1f":"wei3", "4f20":"zhuan4", "4f21":"che1", "4f22":"ya2", "4f23":"xian4", "4f24":"shang1", "4f25":"chang1", "4f26":"lun2", "4f27":"cang1---chen5", "4f28":"xun4", "4f29":"xin4", "4f2a":"wei3", "4f2b":"zhu4", "4f2c":"chi3", "4f2d":"xuan2", "4f2e":"nao2---nu3", "4f2f":"bo2---bai3", "4f30":"gu1---gu4", "4f31":"ni3", "4f32":"ni4", "4f33":"xie4", "4f34":"ban4", "4f35":"xu4", "4f36":"ling2", "4f37":"zhou4", "4f38":"shen1", "4f39":"qu1", "4f3a":"si4---ci4", "4f3b":"beng1", "4f3c":"si4---shi4", "4f3d":"jia1---qie2", "4f3e":"pi1", "4f3f":"yi4", "4f40":"si4---shi4", "4f41":"ai3", "4f42":"zheng1---zheng4", "4f43":"dian4---tian2", "4f44":"han2", "4f45":"mai4", "4f46":"dan4", "4f47":"zhu4", "4f48":"bu4", "4f49":"qu1", "4f4a":"bi3", "4f4b":"shao4", "4f4c":"ci3", "4f4d":"wei4", "4f4e":"di1", "4f4f":"zhu4", "4f50":"zuo3",
"4f51":"you4", "4f52":"yang1", "4f53":"ti3", "4f54":"zhan4", "4f55":"he2---he4", "4f56":"bi4", "4f57":"tuo2", "4f58":"she2", "4f59":"yu2---tu2", "4f5a":"yi4---die2", "4f5b":"fo2---fu2", "4f5c":"zuo1", "4f5d":"kou4", "4f5e":"ning4", "4f5f":"tong2", "4f60":"ni3", "4f61":"xuan1---san3", "4f62":"ju4", "4f63":"yong4---yong1", "4f64":"wa3", "4f65":"qian1", "4f66":"---", "4f67":"ka3", "4f68":"---", "4f69":"pei4", "4f6a":"huai2", "4f6b":"he4", "4f6c":"lao3", "4f6d":"xiang2", "4f6e":"ge2", "4f6f":"yang2", "4f70":"bai3", "4f71":"fa3", "4f72":"ming2", "4f73":"jia1", "4f74":"er4---nai4", "4f75":"bing4", "4f76":"ji2", "4f77":"heng2", "4f78":"huo2", "4f79":"gui3", "4f7a":"quan2", "4f7b":"tiao1---tiao2", "4f7c":"jiao3---jia3", "4f7d":"ci4", "4f7e":"yi4", "4f7f":"shi3", "4f80":"xing2", "4f81":"shen1", "4f82":"tuo1", "4f83":"kan3", "4f84":"zhi2", "4f85":"gai1---kai1", "4f86":"lai2", "4f87":"yi2", "4f88":"chi3", "4f89":"kua1---kua3", "4f8a":"guang1", "4f8b":"li4", "4f8c":"yin1", "4f8d":"shi4", "4f8e":"mi3", "4f8f":"zhu1", "4f90":"xu4", "4f91":"you4", "4f92":"an1", "4f93":"lu4", "4f94":"mou2", "4f95":"er2", "4f96":"lun2", "4f97":"dong4", "4f98":"cha4", "4f99":"chi4", "4f9a":"xun4", "4f9b":"gong1---gong4", "4f9c":"zhou1", "4f9d":"yi1", "4f9e":"ru3", "4f9f":"jian4", "4fa0":"xia2", "4fa1":"jia4---jie4", "4fa2":"zai4", "4fa3":"lu":"3", "4fa4":"---", "4fa5":"jiao3---yao2", "4fa6":"zhen1", "4fa7":"ce4", "4fa8":"qiao2", "4fa9":"kuai4", "4faa":"chai2", "4fab":"ning4", "4fac":"nong2", "4fad":"jin3---jin4", "4fae":"wu3", "4faf":"hou2---hou4", "4fb0":"jiong3", "4fb1":"cheng3", "4fb2":"zhen4", "4fb3":"cuo4", "4fb4":"chou3", "4fb5":"qin1", "4fb6":"lu":"3", "4fb7":"ju2", "4fb8":"shu4", "4fb9":"ting3", "4fba":"shen4", "4fbb":"tuo1", "4fbc":"bo2", "4fbd":"nan2", "4fbe":"hao1", "4fbf":"bian4---pian2", "4fc0":"tui3", "4fc1":"yu3", "4fc2":"xi4", "4fc3":"cu4", "4fc4":"e2---e4", "4fc5":"qiu2", "4fc6":"xu2", "4fc7":"kuang3", "4fc8":"ku4", "4fc9":"wu2", "4fca":"jun4", "4fcb":"yi4", "4fcc":"fu3", "4fcd":"lang2", "4fce":"zu3", "4fcf":"qiao4", "4fd0":"li4", "4fd1":"yong3", "4fd2":"hun4", "4fd3":"jing4", "4fd4":"xian4", "4fd5":"san4", "4fd6":"pai3", "4fd7":"su2", "4fd8":"fu2", "4fd9":"xi1", "4fda":"li3", "4fdb":"mian3", "4fdc":"ping1---ping2", "4fdd":"bao3", "4fde":"yu2", "4fdf":"si4---qi2", "4fe0":"xia2", "4fe1":"xin4---shen1", "4fe2":"xiu1", "4fe3":"yu3", "4fe4":"ti4", "4fe5":"che1", "4fe6":"chou2", "4fe7":"---", "4fe8":"yan3", "4fe9":"lia3---liang3", "4fea":"li4", "4feb":"lai2", "4fec":"si1", "4fed":"jian3",
"4fee":"xiu1", "4fef":"fu3", "4ff0":"he2", "4ff1":"ju4---ju1", "4ff2":"xiao4", "4ff3":"pai2", "4ff4":"jian4", "4ff5":"biao3", "4ff6":"chu4", "4ff7":"fei4", "4ff8":"feng4", "4ff9":"ya4", "4ffa":"an3", "4ffb":"bei4", "4ffc":"yu4---zhou1", "4ffd":"xin1", "4ffe":"bi3", "4fff":"chi2", "5000":"chang1", "5001":"zhi1", "5002":"bing4", "5003":"zan2", "5004":"yao2", "5005":"cui4", "5006":"lia3---liang3", "5007":"wan3", "5008":"lai2", "5009":"cang1", "500a":"zong3", "500b":"ge4", "500c":"guan1", "500d":"bei4", "500e":"tian1", "500f":"shu1", "5010":"shu1", "5011":"men5---men2", "5012":"dao3---dao4", "5013":"tan2", "5014":"jue2---jue4", "5015":"chui2", "5016":"xing4", "5017":"peng2", "5018":"tang3---chang2", "5019":"hou4", "501a":"yi3", "501b":"qi1", "501c":"ti4", "501d":"gan4", "501e":"jing4---liang4", "501f":"jie4", "5020":"xu1", "5021":"chang4---chang1", "5022":"jie2", "5023":"fang3", "5024":"zhi2", "5025":"kong1---kong3", "5026":"juan4", "5027":"zong1", "5028":"ju4", "5029":"qian4", "502a":"ni2", "502b":"lun2", "502c":"zhuo1---zhuo2", "502d":"wo1", "502e":"luo3", "502f":"song1", "5030":"leng2", "5031":"hun4", "5032":"dong1", "5033":"zi4", "5034":"ben4", "5035":"wu3", "5036":"ju4---ju1", "5037":"nai4", "5038":"cai3", "5039":"jian3", "503a":"zhai4", "503b":"ye1", "503c":"zhi2", "503d":"sha4", "503e":"qing1", "503f":"---", "5040":"ying1", "5041":"cheng1---cheng4", "5042":"qian2", "5043":"yan3", "5044":"nuan4", "5045":"zhong4", "5046":"chun3", "5047":"jia3---jia4", "5048":"jie2---ji4", "5049":"wei3", "504a":"yu3", "504b":"bing4", "504c":"ruo4", "504d":"ti2", "504e":"wei1", "504f":"pian1", "5050":"yan4", "5051":"feng1", "5052":"tang3", "5053":"wo4", "5054":"e4", "5055":"xie2", "5056":"che3", "5057":"sheng3", "5058":"kan3", "5059":"di4", "505a":"zuo4", "505b":"cha1", "505c":"ting2", "505d":"bei1", "505e":"ye4", "505f":"huang2", "5060":"yao3", "5061":"zhan4", "5062":"qiu1", "5063":"yan1",
"5064":"you2", "5065":"jian4", "5066":"xu3", "5067":"zha1", "5068":"chai1", "5069":"fu4", "506a":"bi1", "506b":"zhi4", "506c":"zong3", "506d":"mian3", "506e":"ji2", "506f":"yi3", "5070":"xie4", "5071":"xun2", "5072":"si1", "5073":"duan1", "5074":"ce4", "5075":"zhen1", "5076":"ou3", "5077":"tou1", "5078":"tou1", "5079":"bei4", "507a":"za2---zan2", "507b":"lu":"3---lou2", "507c":"jie2", "507d":"wei4", "507e":"fen4", "507f":"chang2", "5080":"gui1---kui3", "5081":"sou3", "5082":"chi3", "5083":"su4", "5084":"xia1", "5085":"fu4", "5086":"yuan4", "5087":"rong3", "5088":"li4", "5089":"ru4", "508a":"yun3", "508b":"gou4", "508c":"ma4", "508d":"bang4---bang1", "508e":"dian1", "508f":"tang2", "5090":"hao1", "5091":"jie2", "5092":"xi1", "5093":"shan1", "5094":"qian4", "5095":"jue2", "5096":"cang1---chen5", "5097":"chu4", "5098":"san3", "5099":"bei4", "509a":"xiao4", "509b":"yong2", "509c":"yao2", "509d":"ta4", "509e":"suo1", "509f":"wang1", "50a0":"fa2", "50a1":"bing4---bing1", "50a2":"jia1", "50a3":"tai4", "50a4":"zai4", "50a5":"tang3", "50a6":"---", "50a7":"bin1", "50a8":"chu3", "50a9":"nuo2", "50aa":"zan1", "50ab":"lei3", "50ac":"cui1", "50ad":"yong1---yong4", "50ae":"zao1", "50af":"zong3", "50b0":"peng2", "50b1":"song3", "50b2":"ao4", "50b3":"chuan2---zhuan4", "50b4":"yu3", "50b5":"zhai4", "50b6":"zu2", "50b7":"shang1", "50b8":"qiang3", "50b9":"qiang1", "50ba":"chi4", "50bb":"sha3", "50bc":"han4", "50bd":"zhang1", "50be":"qing1", "50bf":"yan4", "50c0":"di4", "50c1":"xi1", "50c2":"lu":"3---lou2", "50c3":"bei4", "50c4":"piao1", "50c5":"jin3---jin4", "50c6":"lian3", "50c7":"lu4", "50c8":"man4", "50c9":"qian1", "50ca":"xian1", "50cb":"qiu2", "50cc":"ying2", "50cd":"dong4", "50ce":"zhuan4", "50cf":"xiang4", "50d0":"shan3", "50d1":"qiao2", "50d2":"jiong3", "50d3":"tui2", "50d4":"zun3", "50d5":"pu2---pu1", "50d6":"xi1", "50d7":"lao4", "50d8":"chang3", "50d9":"guang1", "50da":"liao2", "50db":"qi1", "50dc":"deng4", "50dd":"chan2", "50de":"wei3", "50df":"zhang3", "50e0":"fan1", "50e1":"hui4", "50e2":"chuan3", "50e3":"tie3", "50e4":"dan4", "50e5":"jiao3---yao2", "50e6":"jiu4", "50e7":"seng1", "50e8":"fen4", "50e9":"xian4", "50ea":"jue2", "50eb":"e4", "50ec":"jiao1", "50ed":"jian4", "50ee":"tong2", "50ef":"lin2", "50f0":"bo2---fu2", "50f1":"gu4", "50f2":"xian1", "50f3":"su4", "50f4":"xian4", "50f5":"jiang1", "50f6":"min3", "50f7":"ye4", "50f8":"jin4", "50f9":"jia4", "50fa":"qiao4", "50fb":"pi4", "50fc":"feng1", "50fd":"zhou4", "50fe":"ai4", "50ff":"sai4", "5100":"yi2", "5101":"jun4---juan4", "5102":"nong2", "5103":"shan4", "5104":"yi4", "5105":"dang1", "5106":"jing3", "5107":"xuan1", "5108":"kuai4", "5109":"jian3", "510a":"chu4", "510b":"dan1", "510c":"jiao3", "510d":"sha3", "510e":"zai4---zai3", "510f":"---", "5110":"bin4---bin1", "5111":"an4", "5112":"ru2", "5113":"tai2", "5114":"chou2", "5115":"chai2", "5116":"lan2", "5117":"ni3", "5118":"jin3", "5119":"qian1", "511a":"meng2", "511b":"wu3", "511c":"neng2", "511d":"qiong2", "511e":"ni3",
};
var roo = new RegExp(Object.keys(mapUni1).join("|"),"gi");
pinyin = chiniuni.toLowerCase().replace(roo, function(matched){
return mapUni1[matched];
});
document.getElementById("bbb").innerHTML = pinyin
See it here: https://jsfiddle.net/drm65da5/
P.S: I know about difficulties of arrays but I have my own reasons to do this only in this way, so please do not suggest to use different methods. Thanks.
The long object has an extra colon at:
"507b":"lu":"3---lou2",
^
And probably more. I can't provide a solution because it's up to you which of the strings above is the key and its value. Generally, always look at the console, first. It's the initial place for debugging.

Parsing Calendar blob from Oracle Primavera using Javascript

Oracle Primavera stores Calendar data as blob in base64 encoded format, which when decoded gives the following content,
(0||CalendarData()( (0||DaysOfWeek()( (0||1()()) (0||2()( (0||0(s|08:00|f|16:00)()))) (0||3()( (0||0(s|08:00|f|16:00)()))) (0||4()( (0||0(s|08:00|f|16:00)()))) (0||5()( (0||0(s|08:00|f|16:00)()))) (0||6()( (0||0(s|08:00|f|16:00)()))) (0||7()()))) (0||VIEW(ShowTotal|Y)()) (0||Exceptions()( (0||0(d|39814)()) (0||1(d|39815)()) (0||2(d|39818)()) (0||3(d|39819)()) (0||4(d|39820)()) (0||5(d|39821)()) (0||6(d|39822)()) (0||7(d|39825)()) (0||8(d|39826)()) (0||9(d|39827)()) (0||10(d|39828)()) (0||11(d|39829)()) (0||12(d|39832)()) (0||13(d|39833)()) (0||14(d|39834)()) (0||15(d|39835)()) (0||16(d|39836)()) (0||17(d|39839)()) (0||18(d|39840)()) (0||19(d|39841)()) (0||20(d|39842)()) (0||21(d|39843)()) (0||22(d|39846)()) (0||23(d|39847)()) (0||24(d|39848)()) (0||25(d|39849)()) (0||26(d|39850)()) (0||27(d|39853)()) (0||28(d|39854)()) (0||29(d|39855)()) (0||30(d|39856)()) (0||31(d|39857)()) (0||32(d|39860)()) (0||33(d|39861)()) (0||34(d|39862)()) (0||35(d|39863)()) (0||36(d|39864)()) (0||37(d|39867)()) (0||38(d|39868)()) (0||39(d|39869)()) (0||40(d|39870)()) (0||41(d|39871)()) (0||42(d|39874)()) (0||43(d|39875)()) (0||44(d|39876)()) (0||45(d|39877)()) (0||46(d|39878)()) (0||47(d|39881)()) (0||48(d|39882)()) (0||49(d|39883)()) (0||50(d|39884)()) (0||51(d|39885)()) (0||52(d|39888)()) (0||53(d|39889)()) (0||54(d|39890)()) (0||55(d|39891)()) (0||56(d|39892)()) (0||57(d|39895)()) (0||58(d|39896)()) (0||59(d|39897)()) (0||60(d|39898)()) (0||61(d|39899)()) (0||62(d|39902)()) (0||63(d|39903)()) (0||64(d|39923)()) (0||65(d|39958)()) (0||66(d|39997)()) (0||67(d|40063)()) (0||68(d|40098)()) (0||69(d|40128)()) (0||70(d|40133)()) (0||71(d|40134)()) (0||72(d|40135)()) (0||73(d|40136)()) (0||74(d|40137)()) (0||75(d|40140)()) (0||76(d|40141)()) (0||77(d|40142)()) (0||78(d|40143)()) (0||79(d|40144)()) (0||80(d|40147)()) (0||81(d|40148)()) (0||82(d|40149)()) (0||83(d|40150)()) (0||84(d|40151)()) (0||85(d|40154)()) (0||86(d|40155)()) (0||87(d|40156)()) (0||88(d|40157)()) (0||89(d|40158)()) (0||90(d|40161)()) (0||91(d|40162)()) (0||92(d|40163)()) (0||93(d|40164)()) (0||94(d|40165)()) (0||95(d|40168)()) (0||96(d|40169)()) (0||97(d|40170)()) (0||98(d|40171)()) (0||99(d|40172)()) (0||100(d|40175)()) (0||101(d|40176)()) (0||102(d|40177)()) (0||103(d|40178)()) (0||104(d|40179)()) (0||105(d|40182)()) (0||106(d|40183)()) (0||107(d|40184)()) (0||108(d|40185)()) (0||109(d|40186)()) (0||110(d|40189)()) (0||111(d|40190)()) (0||112(d|40191)()) (0||113(d|40192)()) (0||114(d|40193)()) (0||115(d|40196)()) (0||116(d|40197)()) (0||117(d|40198)()) (0||118(d|40199)()) (0||119(d|40200)()) (0||120(d|40203)()) (0||121(d|40204)()) (0||122(d|40205)()) (0||123(d|40206)()) (0||124(d|40207)()) (0||125(d|40210)()) (0||126(d|40211)()) (0||127(d|40212)()) (0||128(d|40213)()) (0||129(d|40214)()) (0||130(d|40217)()) (0||131(d|40218)()) .....
How can I read the dates from this variable ? I need to convert it into JSON to be used by the script. I need all the exceptions - the value and date ( For instance, 131 is the exception and 40218 is the date ). Thank you,
This is how I did this in PHP
Parse the data with a nested parenthesis class
https://gist.github.com/Xeoncross/4710324
Then deal with the time intervals
if( preg_match('~^s\|([0-9]+):([0-9]+)\|f\|([0-9]+):([0-9]+)$~', $string, $match) )
{ // Start and finish times
$interval[] = array(
's' => array(
't' => $match[1].':'.$match[2],
'h' => (int)$match[1],
'm' => (int)$match[2],
),
'f' => array(
't' => $match[3].':'.$match[4],
'h' => (int)$match[3],
'm' => (int)$match[4],
)
);
}
MPXJ reads this data. The relevant code can be found starting here https://github.com/joniles/mpxj/blob/master/src/net/sf/mpxj/primavera/PrimaveraReader.java#L181 which I suspect you can translate easily enough into Javascript.

Categories

Resources