PDA

View Full Version : How to refer to JSON array



jdadwilson
04-08-2014, 04:27 PM
I have the following JSON returned from a database query.


[{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\"InvInfo\":{\"Number\":\"1402001\",\"Date\":\"2014-03-18\",\"FmDate\":\"2014-02-01\",\"ToDate\":\"2014-02-28\",\"Type\":\"DRAFT\",\"Cycle\":\"E\",\"Posted\":\"N\",\"Memo\":\"\",\"Total\":6877.5,\"Outstanding\":10716.29,\"TotalPaid\":0,\"TotalCurrent\":0,\"Total30Days\":0,\"Total60Days\":0,\"Total90Days\":10716.29},\"ProjInfo\":{\"ID\":\"0420.020\",\"Name\":\"Old Republic Title: Concord\",\"ValueOrig\":\"0.00\",\"ValueAmend\":\"0.00\",\"ValueReimb\":\"0.00\",\"Mult\":\"0.15\",\"RateGroup\":\"8\",\"ReferTo\":\"Mr. Neil Wirth\",\"PrintPB\":\"N\",\"StartDate\":\"2013-11-07\"},\"CompInfo\":{\"Name\":\"Old Republic Title Company\",\"Address1\":\"1001 Galaxy Way, Suite 100\",\"Address2\":null,\"Address3\":null,\"City\":\"Concord\",\"State\":\"CA\",\"ZipCode\":\"94520\",\"Contact\":\"Accounts Payable\"},\"SqFtInfo\":[],\"HrlyInfo\":{\"1\":{\"Phase\":\"216\",\"Description\":\"Additional Services\",\"Date\":\"2014-02-03\",\"EmpNum\":\"C183\",\"StaffDesc\":\"Professional Staff I\",\"Hours\":\"65.50\",\"Rate\":105,\"Comment\":\"No comment\"},\"2\":{\"Phase\":\"216\",\"Comment\":\"BilledToDate\",\"Amount\":3330}},\"FxFeInfo\":[],\"ConsInfo\":[],\"ExpsInfo\":[],\"AdjsInfo\":{\"Services\":{\"Text\":\"(Amount Previously Billed - $0.00) Adjustment\",\"PrevBilled\":0,\"TypeTotal\":6877.5,\"Amount\":0,\"Total\":6877.5},\"Expenses\":{\"Text\":\"Adjustment\",\"PrevBilled\":0,\"TypeTotal\":0,\"Amount\":0,\"Total\":0}}}"}]

You will note that within the JSON is a JSON (invJson). My question is how do I obtain the value of a field within the embedded JSON area? For example how would I get the value of 'Name' within the 'ProjInfo' of the 'invJson'?

To get the 'invNum' I use


var oInvoice = $.parseJSON(data);
var gInv_Num = oInvoice[0].invNum;


I have tried everything that I can think of to no avail.

TIA for any assistance.
jdadwilson

traq
04-08-2014, 05:03 PM
That's a JSON string encoded as a JSON string (i.e., it's double-encoded). You'll need to parse it again.


var oInvoice = $.parseJSON(data);
var gInv_Num = $.parseJSON( oInvoice[0].invNum );

Just as a side note, it would be good advice to not store JSON in a database. You should store the actual data in a database, and then json-encode it when needed. You'd probably be able to avoid double-encoding/decoding things that way, too.

jscheuer1
04-08-2014, 05:28 PM
$.parseJSON() is for a string representing a strict JSON object. What you have in your post ("I have the following JSON") is a literal array.

If that's already an array, you don't need $.parseJSON(). If it's a string, it's malformed JSON and must be processed some other way. If it's something else, well we shall see. We need to find out what you have before trying to process it:


alert(typeof data);
alert(data.constructor);
var oInvoice = $.parseJSON(data);
var gInv_Num = oInvoice[0].invNum;

Let me know what those two alerts give you. And there should be a way to proceed from there.

traq
04-08-2014, 06:20 PM
$.parseJSON() is for a string representing a strict JSON object. What you have in your post ("I have the following JSON") is a literal array.

If that's already an array, you don't need $.parseJSON(). If it's a string, it's malformed JSON and must be processed some other way…

hmm… I had assumed that it actually was a string (e.g., a raw HTTP response) and I added quotes around it when I tested. However, I did my testing with PHP's native functions—I see now that it does not parse correctly in JS. However, JSONlint (http://jsonlint.com) says it's valid…?

jscheuer1
04-08-2014, 07:50 PM
Well, it might have to be parsed server side then. A relatively simple PHP script could be called via AJAX or jQuery.ajax if need be.

jscheuer1
04-09-2014, 03:49 AM
OK, I've been playing around with this. Note I've replaced [ and ] with ' and ' for the raw string in all three below cases. In pure PHP, you can do:


<pre>
<?php
$json = '{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\"InvInfo\":{\"Number\":\"1402001\",\"Date\":\"2014-03-18\",\"FmDate\":\"2014-02-01\",\"ToDate\":\"2014-02-28\",\"Type\":\"DRAFT\",\"Cycle\":\"E\",\"Posted\":\"N\",\"Memo\":\"\",\"Total\":6877.5,\"Outstanding\":10716.29,\"TotalPaid\":0,\"TotalCurrent\":0,\"Total30Days\":0,\"Total60Days\":0,\"Total90Days\":10716.29},\"ProjInfo\":{\"ID\":\"0420.020\",\"Name\":\"Old Republic Title: Concord\",\"ValueOrig\":\"0.00\",\"ValueAmend\":\"0.00\",\"ValueReimb\":\"0.00\",\"Mult\":\"0.15\",\"RateGroup\":\"8\",\"ReferTo\":\"Mr. Neil Wirth\",\"PrintPB\":\"N\",\"StartDate\":\"2013-11-07\"},\"CompInfo\":{\"Name\":\"Old Republic Title Company\",\"Address1\":\"1001 Galaxy Way, Suite 100\",\"Address2\":null,\"Address3\":null,\"City\":\"Concord\",\"State\":\"CA\",\"ZipCode\":\"94520\",\"Contact\":\"Accounts Payable\"},\"SqFtInfo\":[],\"HrlyInfo\":{\"1\":{\"Phase\":\"216\",\"Description\":\"Additional Services\",\"Date\":\"2014-02-03\",\"EmpNum\":\"C183\",\"StaffDesc\":\"Professional Staff I\",\"Hours\":\"65.50\",\"Rate\":105,\"Comment\":\"No comment\"},\"2\":{\"Phase\":\"216\",\"Comment\":\"BilledToDate\",\"Amount\":3330}},\"FxFeInfo\":[],\"ConsInfo\":[],\"ExpsInfo\":[],\"AdjsInfo\":{\"Services\":{\"Text\":\"(Amount Previously Billed - $0.00) Adjustment\",\"PrevBilled\":0,\"TypeTotal\":6877.5,\"Amount\":0,\"Total\":6877.5},\"Expenses\":{\"Text\":\"Adjustment\",\"PrevBilled\":0,\"TypeTotal\":0,\"Amount\":0,\"Total\":0}}}"}';
$jsonobj = json_decode($json, true);
$jsonobj['invJson'] = json_decode($jsonobj['invJson'], true);
print_r($jsonobj);
echo '<br>';
echo $jsonobj['invId'];
?>
</pre>

In jQuery you can do (string as is except for replacing the square brackets with single quote marks):


var rawjson = '{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\"InvInfo\":{\"Number\":\"1402001\",\"Date\":\"2014-03-18\",\"FmDate\":\"2014-02-01\",\"ToDate\":\"2014-02-28\",\"Type\":\"DRAFT\",\"Cycle\":\"E\",\"Posted\":\"N\",\"Memo\":\"\",\"Total\":6877.5,\"Outstanding\":10716.29,\"TotalPaid\":0,\"TotalCurrent\":0,\"Total30Days\":0,\"Total60Days\":0,\"Total90Days\":10716.29},\"ProjInfo\":{\"ID\":\"0420.020\",\"Name\":\"Old Republic Title: Concord\",\"ValueOrig\":\"0.00\",\"ValueAmend\":\"0.00\",\"ValueReimb\":\"0.00\",\"Mult\":\"0.15\",\"RateGroup\":\"8\",\"ReferTo\":\"Mr. Neil Wirth\",\"PrintPB\":\"N\",\"StartDate\":\"2013-11-07\"},\"CompInfo\":{\"Name\":\"Old Republic Title Company\",\"Address1\":\"1001 Galaxy Way, Suite 100\",\"Address2\":null,\"Address3\":null,\"City\":\"Concord\",\"State\":\"CA\",\"ZipCode\":\"94520\",\"Contact\":\"Accounts Payable\"},\"SqFtInfo\":[],\"HrlyInfo\":{\"1\":{\"Phase\":\"216\",\"Description\":\"Additional Services\",\"Date\":\"2014-02-03\",\"EmpNum\":\"C183\",\"StaffDesc\":\"Professional Staff I\",\"Hours\":\"65.50\",\"Rate\":105,\"Comment\":\"No comment\"},\"2\":{\"Phase\":\"216\",\"Comment\":\"BilledToDate\",\"Amount\":3330}},\"FxFeInfo\":[],\"ConsInfo\":[],\"ExpsInfo\":[],\"AdjsInfo\":{\"Services\":{\"Text\":\"(Amount Previously Billed - $0.00) Adjustment\",\"PrevBilled\":0,\"TypeTotal\":6877.5,\"Amount\":0,\"Total\":6877.5},\"Expenses\":{\"Text\":\"Adjustment\",\"PrevBilled\":0,\"TypeTotal\":0,\"Amount\":0,\"Total\":0}}}"}';
var jsonspliton = ',"invJson"';
var jsonar = rawjson.split(jsonspliton);
var jsonobj = $.parseJSON(jsonar[0] + '}');
var raw2 = jsonar[1].substring(jsonar[1].indexOf('{'), jsonar[1].lastIndexOf('"'));
var jsonobj2 = $.parseJSON(raw2);
jsonobj['invJson'] = jsonobj2;
document.write(jsonobj['invJson']['InvInfo']['FmDate']);

Or (also in jQuery, string double escaped before processing):


var rawjson = '{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\\"InvInfo\\":{\\"Number\\":\\"1402001\\",\\"Date\\":\\"2014-03-18\\",\\"FmDate\\":\\"2014-02-01\\",\\"ToDate\\":\\"2014-02-28\\",\\"Type\\":\\"DRAFT\\",\\"Cycle\\":\\"E\\",\\"Posted\\":\\"N\\",\\"Memo\\":\\"\\",\\"Total\\":6877.5,\\"Outstanding\\":10716.29,\\"TotalPaid\\":0,\\"TotalCurrent\\":0,\\"Total30Days\\":0,\\"Total60Days\\":0,\\"Total90Days\\":10716.29},\\"ProjInfo\\":{\\"ID\\":\\"0420.020\\",\\"Name\\":\\"Old Republic Title: Concord\\",\\"ValueOrig\\":\\"0.00\\",\\"ValueAmend\\":\\"0.00\\",\\"ValueReimb\\":\\"0.00\\",\\"Mult\\":\\"0.15\\",\\"RateGroup\\":\\"8\\",\\"ReferTo\\":\\"Mr. Neil Wirth\\",\\"PrintPB\\":\\"N\\",\\"StartDate\\":\\"2013-11-07\\"},\\"CompInfo\\":{\\"Name\\":\\"Old Republic Title Company\\",\\"Address1\\":\\"1001 Galaxy Way, Suite 100\\",\\"Address2\\":null,\\"Address3\\":null,\\"City\\":\\"Concord\\",\\"State\\":\\"CA\\",\\"ZipCode\\":\\"94520\\",\\"Contact\\":\\"Accounts Payable\\"},\\"SqFtInfo\\":[],\\"HrlyInfo\\":{\\"1\\":{\\"Phase\\":\\"216\\",\\"Description\\":\\"Additional Services\\",\\"Date\\":\\"2014-02-03\\",\\"EmpNum\\":\\"C183\\",\\"StaffDesc\\":\\"Professional Staff I\\",\\"Hours\\":\\"65.50\\",\\"Rate\\":105,\\"Comment\\":\\"No comment\\"},\\"2\\":{\\"Phase\\":\\"216\\",\\"Comment\\":\\"BilledToDate\\",\\"Amount\\":3330}},\\"FxFeInfo\\":[],\\"ConsInfo\\":[],\\"ExpsInfo\\":[],\\"AdjsInfo\\":{\\"Services\\":{\\"Text\\":\\"(Amount Previously Billed - $0.00) Adjustment\\",\\"PrevBilled\\":0,\\"TypeTotal\\":6877.5,\\"Amount\\":0,\\"Total\\":6877.5},\\"Expenses\\":{\\"Text\\":\\"Adjustment\\",\\"PrevBilled\\":0,\\"TypeTotal\\":0,\\"Amount\\":0,\\"Total\\":0}}}"}';
var jsonobj = $.parseJSON(rawjson);
jsonobj['invJson'] = $.parseJSON(jsonobj['invJson']);
document.write(jsonobj['invJson']['InvInfo']['FmDate']);

To use the PHP method in your current code you would have to go to the PHP code each time via an AJAX call for each property you might want.

Splitting the string as in the first jQuery method should be able to be performed on the data returned in your function more or less as is. Using the second jQuery method would require (I think) double escaping on the server side before passing it to jQuery. I don't think you could double escape it in javascript/jQuery.

In both jQuery cases [] need to be removed if they are in fact in the string. Single quotes need not be added if the json is passed as a string.

jscheuer1
04-09-2014, 03:19 PM
I've now done a bit more on this. You have to lose the square brackets, they're invalid even in PHP (except perhaps if the expression is treated initially as a pure array in more recent versions of PHP which I believe might accept array literals, even then the contained JSON string would probably need single quotes around it). In javascript, they can serve no valid purpose.

That said, I've refined all three of my previous methods to use RegEx to recognize a single nested JSON string and if present decode/parse it as well into the containing JSON object without having to know in advance what it's name is. If there is no nested JSON, that will be decoded/parsed normally. If there are more than one nested JSON string, it will not work, but something could probably be worked out to accommodate that by counting the number of matches in the array that the RegEx produces. But that could be trickier than I'm thinking.

Here they are in the same order as before:


<pre>
<?php
$json = '{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\"InvInfo\":{\"Number\":\"1402001\",\"Date\":\"2014-03-18\",\"FmDate\":\"2014-02-01\",\"ToDate\":\"2014-02-28\",\"Type\":\"DRAFT\",\"Cycle\":\"E\",\"Posted\":\"N\",\"Memo\":\"\",\"Total\":6877.5,\"Outstanding\":10716.29,\"TotalPaid\":0,\"TotalCurrent\":0,\"Total30Days\":0,\"Total60Days\":0,\"Total90Days\":10716.29},\"ProjInfo\":{\"ID\":\"0420.020\",\"Name\":\"Old Republic Title: Concord\",\"ValueOrig\":\"0.00\",\"ValueAmend\":\"0.00\",\"ValueReimb\":\"0.00\",\"Mult\":\"0.15\",\"RateGroup\":\"8\",\"ReferTo\":\"Mr. Neil Wirth\",\"PrintPB\":\"N\",\"StartDate\":\"2013-11-07\"},\"CompInfo\":{\"Name\":\"Old Republic Title Company\",\"Address1\":\"1001 Galaxy Way, Suite 100\",\"Address2\":null,\"Address3\":null,\"City\":\"Concord\",\"State\":\"CA\",\"ZipCode\":\"94520\",\"Contact\":\"Accounts Payable\"},\"SqFtInfo\":[],\"HrlyInfo\":{\"1\":{\"Phase\":\"216\",\"Description\":\"Additional Services\",\"Date\":\"2014-02-03\",\"EmpNum\":\"C183\",\"StaffDesc\":\"Professional Staff I\",\"Hours\":\"65.50\",\"Rate\":105,\"Comment\":\"No comment\"},\"2\":{\"Phase\":\"216\",\"Comment\":\"BilledToDate\",\"Amount\":3330}},\"FxFeInfo\":[],\"ConsInfo\":[],\"ExpsInfo\":[],\"AdjsInfo\":{\"Services\":{\"Text\":\"(Amount Previously Billed - $0.00) Adjustment\",\"PrevBilled\":0,\"TypeTotal\":6877.5,\"Amount\":0,\"Total\":6877.5},\"Expenses\":{\"Text\":\"Adjustment\",\"PrevBilled\":0,\"TypeTotal\":0,\"Amount\":0,\"Total\":0}}}"}';
$jsonobj = json_decode($json, true);
$jsonmatch = preg_match('/, *"([^"]+)" *: *"\{/', $json, $jsonar);
if($jsonmatch){
$jsonobj[$jsonar[1]] = json_decode($jsonobj[$jsonar[1]], true);
}
print_r($jsonobj);
echo '<br>';
echo $jsonobj['invJson']['InvInfo']['FmDate'];
?>
</pre>


var rawjson = '{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\"InvInfo\":{\"Number\":\"1402001\",\"Date\":\"2014-03-18\",\"FmDate\":\"2014-02-01\",\"ToDate\":\"2014-02-28\",\"Type\":\"DRAFT\",\"Cycle\":\"E\",\"Posted\":\"N\",\"Memo\":\"\",\"Total\":6877.5,\"Outstanding\":10716.29,\"TotalPaid\":0,\"TotalCurrent\":0,\"Total30Days\":0,\"Total60Days\":0,\"Total90Days\":10716.29},\"ProjInfo\":{\"ID\":\"0420.020\",\"Name\":\"Old Republic Title: Concord\",\"ValueOrig\":\"0.00\",\"ValueAmend\":\"0.00\",\"ValueReimb\":\"0.00\",\"Mult\":\"0.15\",\"RateGroup\":\"8\",\"ReferTo\":\"Mr. Neil Wirth\",\"PrintPB\":\"N\",\"StartDate\":\"2013-11-07\"},\"CompInfo\":{\"Name\":\"Old Republic Title Company\",\"Address1\":\"1001 Galaxy Way, Suite 100\",\"Address2\":null,\"Address3\":null,\"City\":\"Concord\",\"State\":\"CA\",\"ZipCode\":\"94520\",\"Contact\":\"Accounts Payable\"},\"SqFtInfo\":[],\"HrlyInfo\":{\"1\":{\"Phase\":\"216\",\"Description\":\"Additional Services\",\"Date\":\"2014-02-03\",\"EmpNum\":\"C183\",\"StaffDesc\":\"Professional Staff I\",\"Hours\":\"65.50\",\"Rate\":105,\"Comment\":\"No comment\"},\"2\":{\"Phase\":\"216\",\"Comment\":\"BilledToDate\",\"Amount\":3330}},\"FxFeInfo\":[],\"ConsInfo\":[],\"ExpsInfo\":[],\"AdjsInfo\":{\"Services\":{\"Text\":\"(Amount Previously Billed - $0.00) Adjustment\",\"PrevBilled\":0,\"TypeTotal\":6877.5,\"Amount\":0,\"Total\":6877.5},\"Expenses\":{\"Text\":\"Adjustment\",\"PrevBilled\":0,\"TypeTotal\":0,\"Amount\":0,\"Total\":0}}}"}';
var jsonm = /, *"([^"]+)" *: *"\{/.exec(rawjson);
if(jsonm){
var jsonar = rawjson.split(jsonm[0]);
var jsonobj = $.parseJSON(jsonar[0] + '}');
var raw2 = '{' + jsonar[1].substring(0, jsonar[1].lastIndexOf('"'));
var jsonobj2 = $.parseJSON(raw2);
jsonobj[jsonm[1]] = jsonobj2;
} else {
var jsonobj = $.parseJSON(rawjson);
}
document.write(jsonobj['invJson']['AdjsInfo']['Services']['Text']);

Note - this last (below) is with the double escapes in the nested JSON string, which, again would have to be added on the server side, which can be done with (in PHP) preg_replace('/\\\"/', '\\\\"', $json);


var rawjson = '{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\\"InvInfo\\":{\\"Number\\":\\"1402001\\",\\"Date\\":\\"2014-03-18\\",\\"FmDate\\":\\"2014-02-01\\",\\"ToDate\\":\\"2014-02-28\\",\\"Type\\":\\"DRAFT\\",\\"Cycle\\":\\"E\\",\\"Posted\\":\\"N\\",\\"Memo\\":\\"\\",\\"Total\\":6877.5,\\"Outstanding\\":10716.29,\\"TotalPaid\\":0,\\"TotalCurrent\\":0,\\"Total30Days\\":0,\\"Total60Days\\":0,\\"Total90Days\\":10716.29},\\"ProjInfo\\":{\\"ID\\":\\"0420.020\\",\\"Name\\":\\"Old Republic Title: Concord\\",\\"ValueOrig\\":\\"0.00\\",\\"ValueAmend\\":\\"0.00\\",\\"ValueReimb\\":\\"0.00\\",\\"Mult\\":\\"0.15\\",\\"RateGroup\\":\\"8\\",\\"ReferTo\\":\\"Mr. Neil Wirth\\",\\"PrintPB\\":\\"N\\",\\"StartDate\\":\\"2013-11-07\\"},\\"CompInfo\\":{\\"Name\\":\\"Old Republic Title Company\\",\\"Address1\\":\\"1001 Galaxy Way, Suite 100\\",\\"Address2\\":null,\\"Address3\\":null,\\"City\\":\\"Concord\\",\\"State\\":\\"CA\\",\\"ZipCode\\":\\"94520\\",\\"Contact\\":\\"Accounts Payable\\"},\\"SqFtInfo\\":[],\\"HrlyInfo\\":{\\"1\\":{\\"Phase\\":\\"216\\",\\"Description\\":\\"Additional Services\\",\\"Date\\":\\"2014-02-03\\",\\"EmpNum\\":\\"C183\\",\\"StaffDesc\\":\\"Professional Staff I\\",\\"Hours\\":\\"65.50\\",\\"Rate\\":105,\\"Comment\\":\\"No comment\\"},\\"2\\":{\\"Phase\\":\\"216\\",\\"Comment\\":\\"BilledToDate\\",\\"Amount\\":3330}},\\"FxFeInfo\\":[],\\"ConsInfo\\":[],\\"ExpsInfo\\":[],\\"AdjsInfo\\":{\\"Services\\":{\\"Text\\":\\"(Amount Previously Billed - $0.00) Adjustment\\",\\"PrevBilled\\":0,\\"TypeTotal\\":6877.5,\\"Amount\\":0,\\"Total\\":6877.5},\\"Expenses\\":{\\"Text\\":\\"Adjustment\\",\\"PrevBilled\\":0,\\"TypeTotal\\":0,\\"Amount\\":0,\\"Total\\":0}}}"}';
var jsonobj = $.parseJSON(rawjson);
var jsonm = /, *"([^"]+)" *: *"\{/.exec(rawjson);
if(jsonm){
jsonobj[jsonm[1]] = $.parseJSON(jsonobj[jsonm[1]]);
}
document.write(jsonobj['invJson']['AdjsInfo']['Services']['Text']);

jscheuer1
04-11-2014, 04:23 AM
Here's a more thorough demo of the third method:


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

</head>
<body>
<div id="result"></div>
<script type="text/javascript">
$.ajax({
url: 'json4.php',
cache: false,
success: function(data){
var jsonobj = $.parseJSON(data);
var jsonm = /, *"([^"]+)" *: *"\{/.exec(data);
if(jsonm){
jsonobj[jsonm[1]] = $.parseJSON(jsonobj[jsonm[1]]);
}
$('#result').html(jsonobj['invJson']['AdjsInfo']['Services']['Text']);
},
error: function(o, s, e){
window.console && console.log(s);
}
});
</script>
</body>
</html>

json4.php:


<?php
$json = '{"invId":230,"invNum":"1402001","invDate":"2014-03-18","invProject":"0420.020","invStatus":"DRAFT","invCycle":"E","invPosted":"N","invJson":"{\"InvInfo\":{\"Number\":\"1402001\",\"Date\":\"2014-03-18\",\"FmDate\":\"2014-02-01\",\"ToDate\":\"2014-02-28\",\"Type\":\"DRAFT\",\"Cycle\":\"E\",\"Posted\":\"N\",\"Memo\":\"\",\"Total\":6877.5,\"Outstanding\":10716.29,\"TotalPaid\":0,\"TotalCurrent\":0,\"Total30Days\":0,\"Total60Days\":0,\"Total90Days\":10716.29},\"ProjInfo\":{\"ID\":\"0420.020\",\"Name\":\"Old Republic Title: Concord\",\"ValueOrig\":\"0.00\",\"ValueAmend\":\"0.00\",\"ValueReimb\":\"0.00\",\"Mult\":\"0.15\",\"RateGroup\":\"8\",\"ReferTo\":\"Mr. Neil Wirth\",\"PrintPB\":\"N\",\"StartDate\":\"2013-11-07\"},\"CompInfo\":{\"Name\":\"Old Republic Title Company\",\"Address1\":\"1001 Galaxy Way, Suite 100\",\"Address2\":null,\"Address3\":null,\"City\":\"Concord\",\"State\":\"CA\",\"ZipCode\":\"94520\",\"Contact\":\"Accounts Payable\"},\"SqFtInfo\":[],\"HrlyInfo\":{\"1\":{\"Phase\":\"216\",\"Description\":\"Additional Services\",\"Date\":\"2014-02-03\",\"EmpNum\":\"C183\",\"StaffDesc\":\"Professional Staff I\",\"Hours\":\"65.50\",\"Rate\":105,\"Comment\":\"No comment\"},\"2\":{\"Phase\":\"216\",\"Comment\":\"BilledToDate\",\"Amount\":3330}},\"FxFeInfo\":[],\"ConsInfo\":[],\"ExpsInfo\":[],\"AdjsInfo\":{\"Services\":{\"Text\":\"(Amount Previously Billed - $0.00) Adjustment\",\"PrevBilled\":0,\"TypeTotal\":6877.5,\"Amount\":0,\"Total\":6877.5},\"Expenses\":{\"Text\":\"Adjustment\",\"PrevBilled\":0,\"TypeTotal\":0,\"Amount\":0,\"Total\":0}}}"}';
echo preg_replace('/\\\"/', '\\\\"', $json);
?>