ActionScript String Concatenation in for loop - actionscript-3

So I am struggling with loops.
I have a mobile app with dynamic controls that I add from a sqlite database, it is a list of questions and based on the question type, I add the relevant type of control to the page along with the question, this all works fine.
I then loop through all the controls looking for answers, so I can loop through 60 quesitons and return the values from the relevant textboxes, checkboxes and toggle switches.
The for loop runs like this
if (displayObject is DisplayObjectContainer && currentDepth < maxDepth)
{
for (var i:int = 0; i < DisplayObjectContainer(displayObject).numChildren; i++)
{
traceDisplayList(DisplayObjectContainer(displayObject).getChildAt(i), maxDepth, skipClass, levelSpace + " ", currentDepth + 1);
if (displayObject is TextInput ||displayObject is CheckBox || displayObject is Label || displayObject is ToggleSwitch )
{
if(displayObject["id"] =="QuestionText"&& (i==0))
{
if(displayObject["text"] != null)
{
questionString= (displayObject["text"]);
trace ("Question: " + questionString);
}
}
else if (displayObject["id"] == "QuestionResponse")
{
if(displayObject["text"] != null)
{
answerString = (displayObject["text"]);
trace ("Answer: " + answerString);
}
}
else if (displayObject["id"]== "CheckboxResult")
{
if(displayObject["selected"] != null)
{
checkboxAnswer = (displayObject["selected"]);
trace ("Check / Toggle: " + checkboxAnswer);
}
}
}
}
}
My question is, the results I get back look like this;
questionstring value
answerstring value
checkbox value
what I want is
questionstring value, answerstring value, checkbox value
I cannot for the life of me see how I get these values into 1 row.
Any tips appreciated

Trace just prints info to the console mainly for debugging if you really want all of that on one line in the console you just need to create a string and then add "Question: " + questionString + " Answer: " + answerString + " Check / Toggle: " + checkboxAnswer to the string after you have found them all and then call trace with your string you made. something like this
var mystring:String
mystring="";
if(displayObject["id"] =="QuestionText"&& (i==0))
{
if(displayObject["text"] != null)
{
questionString= (displayObject["text"]);
mystring += "Question: " + questionString;
}
}
else if (displayObject["id"] == "QuestionResponse")
{
if(displayObject["text"] != null)
{
answerString = (displayObject["text"]);
mystring += "Answer: " + answerString;
}
}
else if (displayObject["id"]== "CheckboxResult")
{
if(displayObject["selected"] != null)
{
checkboxAnswer = (displayObject["selected"]);
mystring += "Check / Toggle: " + checkboxAnswer;
}
}
trace(mystring);

Related

html to plaintext with NodeJS on server side

on the server-side, using Nodejs. I receive a text message containing HTML. I want a function that converts the html to plain text. And please don't tell me to add the tag <plaintext> or <pre>. (convert_to_html function doesn't exist in nodejs)
socket.on('echo', (text) => {
plaintext = convert_to_html(text);
socket.emit('echo', {
message: plaintext
});
});
ideal results:
input: <h1>haha i am big</h1>
plaintext(what i want plaintext to be): <h1 &60;haha i am big </h1 &60;
output: <h1>haha i am big</h1>
current result:
input: <h1>haha i am big</h1>
plaintext: <h1>haha i am big</h1>
output: haha i am big
You can use the insertAdjacementHTML method on the browser side, here you go an example
socket.on("response", function (msg) {
const messages = document.getElementById("messages");
messages.insertAdjacentHTML("beforebegin", msg);
window.scrollTo(0, document.body.scrollHeight);
});
still don't have a proper solution. while i wait for one, i will use reserved characters as a temporary solution.
https://devpractical.com/display-html-tags-as-plain-text/#:~:text=You%20can%20show%20HTML%20tags,the%20reader%20on%20the%20browser.
function parse_to_plain_text(html){
var result = "";
for (var i = 0; i < html.length; i++) {
var current_char = html[i];
if (current_char == ' '){
result += " "
}
else if (current_char == '<'){
result += "<"
}
else if (current_char == '>'){
result += ">"
}
else if (current_char == '&'){
result += "&"
}
else if (current_char == '"'){
result += """
}
else if (current_char == "'"){
result += "&apos;"
}
else{
result += current_char;
}
}
return result;
}

Why is FileReferenceList.fileList type NULL on MAC OS

I have an application that uploads files to a server. In the onSelectFile function, I check the file type to see if it is valid. I also have a FileFilter that limits what the user can select, but I wanted to double check that they are uploading a correct file type.
On a PC, I can get the value of type for the file, but on a Mac (Safari, Firefox, Chrome), I get NULL.
Here is the function where I try to get the type
// Called when a file is selected
private function onSelectFile(event:Event):void {
//let's see if we're dealing with a new album or an existing album
var arrFoundList:Array = new Array();
// Get list of files from fileList, make list of files already on upload list
for (var i:Number = 0; i < _arrUploadFiles.length; i++) {
for (var j:Number = 0; j < _refAddFiles.fileList.length; j++) {
if (_arrUploadFiles[i].name == _refAddFiles.fileList[j].name) {
arrFoundList.push(_refAddFiles.fileList[j].name);
_refAddFiles.fileList.splice(j, 1);
j--;
}
}
}
if (_refAddFiles.fileList.length >= 1) {
for (var k:Number = 0; k < _refAddFiles.fileList.length; k++) {
var fileType:String = _refAddFiles.fileList[k].type;
Alert.show("File type: " + fileType.toString() + " | name: " + _refAddFiles.fileList[k].name); //fileType is always NULL on Mac
var validTypes:Array = new Array(".jpg", ".jpeg", ".gif", ".png", ".JPG", ".JPEG", ".GIF", ".PNG");
if (validTypes.indexOf(fileType.toLowerCase()) < 0)
{
Alert.show("The file type: " + fileType + " is not valid (file: " + _refAddFiles.fileList[k].name + "). Valid types are .jpg, .gif, and .png", "Invalid File Type");
continue;
}
//start the upload for each file
var item:OneFile= new OneFile();
item.fileName=_refAddFiles.fileList[k].name;
item.fileSize=_refAddFiles.fileList[k].size;
item.file=_refAddFiles.fileList[k];
_bytesTotal+=_refAddFiles.fileList[k].size;
if (existingalbum.selected)
{
item.album=albums.selectedItem.#aid;
}
fileList.addChild(item);
_files.addItem(item);
_numFiles++;
}
startUpload();
}
else
{
Alert.show("No files were added to the list to be uploaded.");
}
if (arrFoundList.length >= 1) {
Alert.show("The file(s): \n\n• " + arrFoundList.join("\n• ") + "\n\n...are already on the upload list. Please change the filename(s) or pick a different file.", "File(s) already on list");
}
else{ // some comment
}
}
Here is a work-around that I found:
public static function extractFileType(fileName:String):String {
var extensionIndex:Number = fileName.lastIndexOf(".");
if (extensionIndex == -1) {
return "";
} else {
return "." + fileName.substr(extensionIndex + 1,fileName.length);
}
}
http://www.josh-ho.com/as3-mac-filereference-type-workaround/

What is the right way to compare as3 objects using hamcrest

I'm trying to compare two objects to see if they are the same using hamcrest for flex-unit, but when the object has sub objects, it just throws an error:
Error: Expected: (An array containing <[object Object]>
but: an array containing <[object Object]> was <[object Object]>
I want it to do an assertThat(..., hasProperties(...)); on the sub object.
Is there a way to get that or should i create a custom matcher?
EDIT
An example of the object structure i want to test:
var expected:Object = {
number:1.3,
array:[{
prop1:"val1", prop2:"val2"
}]
anObject:{
propA:1, propB:2
},
}
var objectUnderTest:Object = {
number:1.3,
array:[{
prop1:"val1", prop2:"val2"
}]
anObject:{
propA:1, propB:2
},
}
assertThat("should be the same", objectUnderTest, hasProperties(expected));
since the expected and objectUnderTest have the same structure, the test should pass, but is returning the error:
Error: Expected: (An array containing <[object Object]>
but: an array containing <[object Object]> was <[object Object]>
Also, if there is a way to compare two JSON strings will be fine too.
EDIT2
This is my final version after djib help:
package com
{
public function assertEqualsObjects(message:String, object1:Object, object2:Object):Boolean
{
// we have to run it both ways (1-2, 2-1)
return (compare(object1, object2, message + ": object") && compare(object2, object1, message + ": extra"));
}
}
import org.flexunit.asserts.fail;
function compare(object1:Object, object2:Object, parent:String):Boolean
{
var count:int = 0;
for (var s:String in object1)
{
count ++;
if (!object2.hasOwnProperty(s))
{
fail(parent + "." + s + " expected: " + object1[s] + " but was: undefined");
return false;
}
if (!compare(object1[s], object2[s], parent + "." + s))
{
fail(parent + "." + s + " expected: " + object1[s] + " but was: " + object2[s]);
return false;
}
}
if (count == 0 && object1 != object2) // if object has no properties, compare their actual values
{
fail(parent + " expected: " + object1 + " but was: " + object2);
return false;
}
return true;
}
I've put this code together. Recursion is the key ^^
// our two objects to compare ...
var obj1 = {
number:1.3,
array:[{prop1:"val1", prop2:"val2"}],
anObject:{propA:1, propB:2}
};
var obj2 = {
number:1.3,
array:[{prop1:"val1", prop2:"val2"}],
anObject:{propA:1, propB:2}
};
trace(isSame(obj1, obj2)); // -> true
function isSame(object1:Object, object2:Object):Boolean
{
// we have to run it both ways (1-2, 2-1)
return (compare(object1, object2) && compare(object2, object1));
}
function compare(object1:Object, object2:Object):Boolean
{
var count:int = 0;
for (var s:String in object1)
{
count ++;
if (object2[s] == undefined)
return false;
if (!compare(object1[s], object2[s]))
return false;
}
if (count == 0 && object1 != object2) // if object has no properties, compare their actual values
return false;
return true;
}

JsTree with JSON stuck on loading

I am using JSON to display a JsTree. The JSON is being built up as a string via a recursive function. Now I went through a few tests with smaller/less complicated trees and got it to work. I used JSONLint to check for valid JSON and eventually got the correct syntax. Now when I try and display the intended big tree its just stuck with the loading .gif (which used to be because the JSON was incorrect) but after checking it on JSONLint it was correct.
Any possible causes for this? I doubt the tree could be too big or anything.
Recursive Function:
public void getViewTree(ref string tree, Int32? id = null)
{
var topNodes = (from items in db.AssessmentViewItems
select items).Take(1);
#region getChildren via LINQ
if (id == null)
{
topNodes = from items in db.AssessmentViewItems
where items.ParentAssessmentViewItemID == null
&& items.AssessmentViewID == 17
select items;
}
else
{
topNodes = from items in db.AssessmentViewItems
where items.ParentAssessmentViewItemID == id
&& items.AssessmentViewID == 17
select items;
}
#endregion
int counter = 1;
int max = (int)topNodes.Count();
foreach (var node in topNodes)
{
if (node.ParentAssessmentViewItemID == null)
{
{\"id\":\"532topNode\",\"selected\":true},\"children\":[null,
tree += "{\"data\":\"" + node.Title.Trim().Replace("\"","").Replace("("," ").Replace(":"," ").Replace("-"," ").Replace("&","and").Replace("/"," ").Replace("\\"," ").Replace(","," ").Replace("•", " ") + "\",\"attr\":{\"id\":\"" + node.AssessmentViewItemID + "\", \"selected\":true}, \"children\":[";
getViewTree(ref tree, node.AssessmentViewItemID);
tree += "}]";
if (counter < max)
{
tree += "},";
}
}
else if (node.Type.Equals("Legal Topic"))
{
tree += "{\"data\":\"" + node.Title.Trim().Replace("\"", "").Replace("(", " ").Replace(":", " ").Replace("-", " ").Replace("&", "and").Replace("/", " ").Replace("\\", " ").Replace(",", " ").Replace("•", " ") + "\",\"attr\":{\"id\":\"" + node.AssessmentViewItemID + "\", \"selected\":true}";
if (counter < max)
{
tree += "},";
}
}
else
{
var topNodes1 = from items in db.AssessmentViewItems
where items.ParentAssessmentViewItemID == node.AssessmentViewItemID
&& items.AssessmentViewID == 17
select items;
if (topNodes1.Count() > 0)
{
tree += "{\"data\":\"" + node.Title.Trim().Replace("\"", "").Replace("(", " ").Replace(":", " ").Replace("-", " ").Replace("&", "and").Replace("/", " ").Replace("\\", " ").Replace(",", " ").Replace("•", " ") + "\",\"attr\":{\"id\":\"" + node.AssessmentViewItemID + "\", \"selected\":true}, \"children\":[";
}
else
{
tree += "{\"data\":\"" + node.Title.Trim().Replace("\"", "").Replace("(", " ").Replace(":", " ").Replace("-", " ").Replace("&", "and").Replace("/", " ").Replace("\\", " ").Replace(",", " ").Replace("•", " ") + "\",\"attr\":{\"id\":\"" + node.AssessmentViewItemID + "\", \"selected\":true}";
}
getViewTree(ref tree, node.AssessmentViewItemID);
if (topNodes1.Count() > 0)
{
tree += "}]";
}
if (counter < max)
{
tree += "}";
tree += ",";
}
}
counter++;
}
}
JS:
$(function () {
$("#demoTree").jstree({
"json_data": {
"data": treeModel
},
"plugins": ["themes", "json_data", "ui"],
});
});
Calling Recursive Function:
string tree = "[";
getViewTree(ref tree);
tree += "}]";
return View("About", "_Layout", tree);
After using Chrome Dev Tools, the error that I get from it:
Uncaught SyntaxError: Unexpected token ILLEGAL (program):54
Uncaught Neither data nor ajax settings supplied.
I did check it for syntax on JSONLint. Small tree is generated fine without those 2 errors
Problem got solved by using DevExpress tree. Exact same JSON string.

CRM 2011: Getting entity with Javascript

I am working on some CRM 2011 Online customisations and I need to get an entity using javascript.
The entity I need will be based on the ID value of another field (a Contact entity) - this Contact ID I can get fine.
The entity I want is a custom entity. There may be multiple matches based on the Contact ID so I just want to get the first one in the list (order not important)
So far I have looked into a few ways to do this...
OData - I couldn't find enough examples on this as to what query expressions I can create, also I don't know if/how to make this work for custom entities
FetchXML - I can create a nice FetchXML query using the built-in "advanced find" too and would be happy to call this from javascript if anyone can help? I found one promising answer here but I could not see how the "results" return data was being set (Service.Fetch function)
SOAP Request - First thing I tried is a similar method as I could have done in CRM 4 but this does not seem to work. Although the request executes, my result data just seems to be empty. This is all I have code for so if any one can spot a problem with the code below then that would be great.
EDIT: I have spotted some redundant query data (I had removed link opening tags but left closing tags) - since removing this I now get XML result data... however, the where clause does not seem to apply (just get list of all entities)
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
"<soap:Body>" +
"<RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"<query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
"<q1:EntityName>new_vehicle</q1:EntityName>" +
"<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>" +
"<q1:Attribute>new_vehicleid</q1:Attribute>" +
"<q1:Attribute>new_primarydriver</q1:Attribute>" +
"<q1:Attribute>statuscode</q1:Attribute>" +
"<q1:Attribute>new_registration</q1:Attribute>" +
"</q1:Attributes>" +
"</q1:ColumnSet>" +
"<q1:Distinct>false</q1:Distinct>" +
"<q1:Conditions>" +
"<q1:Condition>" +
"<q1:AttributeName>new_primarydriver</q1:AttributeName>" +
"<q1:Operator>Equal</q1:Operator>" +
"<q1:Values>" +
"<q1:Value xmlns:q2='http://microsoft.com/wsdl/types/' xsi:type='q2:guid'>" +
customerID +
"</q1:Value></q1:Values></q1:Condition>" +
"</q1:Conditions>" +
"</query></RetrieveMultiple>" +
"</soap:Body></soap:Envelope>";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var result = xmlHttpRequest.responseXML.xml;
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.async = false;
doc.loadXML(result);
var id = doc.selectSingleNode("//new_vehicleid");
var registration = doc.selectSingleNode("//new_registration");
if(id == null)
return null;
var vehicle = new Array();
value[0] = new Object();
value[0].id = id;
value[0].name = registration;
value[0].entityType = "new_vehicle";
return vehicle;
Sorry about the big code post but hopefully somebody who has a better understanding can help
Firstly, thanks to GlennFerrieLive for his answer post. The samples I found with the Dynamics CRM 2011 SDK (well just one in particular) really helped and the JSON parser included was perfect for the job!
I am posting this answer to give a full example of how I did it with some important comments to pay attention to which may not be so obvious from the SDK examples.
Get selected ID value from lookup field
The aim of my task was to use javascript to get set a lookup field, based on the selected data of another lookup entity. The entity to set is "new_vehicle" and the entity to query on is "customer".
First job is to get the ID value of the contact lookup field...
var customerItem = Xrm.Page.getAttribute("customerid").getValue();
var customerID = customerItem[0].id;
Querying an entity using an ID
Next is the part where I used the customerID value to find the vehicle that is currently assigned to them (the entity I want to use to set a lookup field).
First problem I found was that when querying with OData, the ID value does not seem to work with curly brackets {} - so these need to be removed...
customerID = customerID.replace('{', '').replace('}', '');
Next we get the oDataPath...
var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
Then we can construct the OData query...
var filter = "/new_vehicleSet?" +
"$select=new_vehicleId,new_Registration" +
"&$filter=new_PrimaryDriver/Id eq (guid'" + customerID + "')" +
"&$orderby=new_LastAllocationDate desc" +
"&$top=1";
NOTE: There are a couple of important things to note here...
When using a guid value you must explicitly say it is a guid using (guid'xxx')
When filtering by a lookup entity (e.g. new_PrimaryDriver) you must append the value to query (e.g. Id) - this results in new_PrimaryDriver/Id
Once we have the query setup we can request the data as follows...
var retrieveRecordsReq = new XMLHttpRequest();
retrieveRecordsReq.open("GET", oDataPath + filter, true);
retrieveRecordsReq.setRequestHeader("Accept", "application/json");
retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRecordsReq.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status == 200) {
var retrievedRecords = JSON.parse(retrieveRecordsReq.responseText).d;
if(retrievedRecords.results.length > 0)
{
var vehicle = retrievedRecords.results[0];
SetLookup("new_replacedvehicle", vehicle.new_vehicleId, vehicle.new_Registration, "new_vehicle");
}
}
}
};
retrieveRecordsReq.send();
Note that this is an asynchronous call and the onreadystatechange function will be processed upon completion, in this function we do a couple of checks to see if it was a success and the we parse the resulting JSON data - the JSON.Parse function has been included at the bottom of this post (but is available from the SDK)
Setting a lookup field using the entity queried above
The other function to make note of here is SetLookup which is just a simple helper function I added to set a lookup field. This is as follows...
function SetLookup(fieldName, idValue, textValue, typeValue)
{
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].typename = typeValue;
Xrm.Page.getAttribute(fieldName).setValue(value);
}
JSON parse function
This is the JSON helper function that was used in the above code (JSON.parse), pasted as it was found in the SDK...
if (!this.JSON) { this.JSON = {}; } (function () { function f(n) { return n < 10 ? '0' + n : n; } if (typeof Date.prototype.toJSON !== 'function') { Date.prototype.toJSON = function (key) { return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z' : null; }; String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (key) { return this.valueOf(); }; } var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\' }, rep; function quote(string) { escapable.lastIndex = 0; return escapable.test(string) ? '"' + string.replace(escapable, function (a) { var c = meta[a]; return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }) + '"' : '"' + string + '"'; } function str(key, holder) { var i, k, v, length, mind = gap, partial, value = holder[key]; if (value && typeof value === 'object' && typeof value.toJSON === 'function') { value = value.toJSON(key); } if (typeof rep === 'function') { value = rep.call(holder, key, value); } switch (typeof value) { case 'string': return quote(value); case 'number': return isFinite(value) ? String(value) : 'null'; case 'boolean': case 'null': return String(value); case 'object': if (!value) { return 'null'; } gap += indent; partial = []; if (Object.prototype.toString.apply(value) === '[object Array]') { length = value.length; for (i = 0; i < length; i += 1) { partial[i] = str(i, value) || 'null'; } v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']'; gap = mind; return v; } if (rep && typeof rep === 'object') { length = rep.length; for (i = 0; i < length; i += 1) { k = rep[i]; if (typeof k === 'string') { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } else { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}'; gap = mind; return v; } } if (typeof JSON.stringify !== 'function') { JSON.stringify = function (value, replacer, space) { var i; gap = ''; indent = ''; if (typeof space === 'number') { for (i = 0; i < space; i += 1) { indent += ' '; } } else if (typeof space === 'string') { indent = space; } rep = replacer; if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) { throw new Error('JSON.stringify'); } return str('', { '': value }); }; } if (typeof JSON.parse !== 'function') { JSON.parse = function (text, reviver) { var j; function walk(holder, key) { var k, v, value = holder[key]; if (value && typeof value === 'object') { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = walk(value, k); if (v !== undefined) { value[k] = v; } else { delete value[k]; } } } } return reviver.call(holder, key, value); } text = String(text); cx.lastIndex = 0; if (cx.test(text)) { text = text.replace(cx, function (a) { return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }); } if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '#').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { j = eval('(' + text + ')'); return typeof reviver === 'function' ? walk({ '': j }, '') : j; } throw new SyntaxError('JSON.parse'); }; } } ());