I'm trying to work out what format this data is in, so i can change it. It's just horrible.
a:20:{s:12:"tagline_text";s:0:"";s:8:"gAddress";s:40:"380 North Shore Drive, Pittsburgh, 15212";s:8:"latitude";s:9:"40.445917";s:9:"longitude";s:10:"-80.011324";s:5:"phone";s:0:"";s:5:"email";s:0:"";s:7:"website";s:44:"http://tequilacowboy.com/pittsburgh/wannabs/";s:7:"twitter";s:0:"";s:8:"facebook";s:0:"";s:8:"linkedin";s:0:"";s:11:"google_plus";s:0:"";s:7:"youtube";s:0:"";s:9:"instagram";s:0:"";s:5:"video";s:0:"";s:7:"gallery";N;s:12:"price_status";s:0:"";s:10:"list_price";s:0:"";s:13:"list_price_to";s:0:"";s:15:"claimed_section";s:0:"";s:4:"faqs";a:2:{s:3:"faq";a:1:{i:0;s:0:"";}s:6:"faqans";a:1:{i:0;s:0:"";}}}
Looks like the output of PHP serialize() to me. You may be able to decode it back into an array by writing a PHP script, read the data from its file or whatever, and use unserialize() on it.
I tested this guess:
<?php
// read $string from a file or something
print json_encode(unserialize($string));
Run this PHP code:
php myscript.php | jq .
Output:
{
"tagline_text": "",
"gAddress": "380 North Shore Drive, Pittsburgh, 15212",
"latitude": "40.445917",
"longitude": "-80.011324",
"phone": "",
"email": "",
"website": "http://tequilacowboy.com/pittsburgh/wannabs/",
"twitter": "",
"facebook": "",
"linkedin": "",
"google_plus": "",
"youtube": "",
"instagram": "",
"video": "",
"gallery": null,
"price_status": "",
"list_price": "",
"list_price_to": "",
"claimed_section": "",
"faqs": {
"faq": [
""
],
"faqans": [
""
]
}
}
Related
When I am converting json_encode; It is converting it in correct format, but when I am storing it in cookie; format get changed. I want to store in cookie as it is.
JSON STRING:
{
"ID": "0",
"basicAddress": {
"ID": "0",
"Line1": "327 S Main St",
"Line2": "",
"Line3": "",
"City": "Fitzgerald",
"ZipCode": "31750",
"StateProv": "",
"Country": "",
"stateProv": "GA"
},
"Name": "",
"Latitude": "31.7114886",
"Longitude": "-83.25471970000001",
"IsPreferred": "false"
}
AFTER STORING IN COOKIE:
%7B%22ID%22%3A%220%22%2C%22basicAddress%22%3A%7B%22ID%22%3A%220%22%2C%22Line1%22%3A%22327+S+Main+St%22%2C%22Line2%22%3A%22%22%2C%22Line3%22%3A%22%22%2C%22City%22%3A%22Fitzgerald%22%2C%22ZipCode%22%3A%2231750%22%2C%22StateProv%22%3A%22%22%2C%22Country%22%3A%22%22%2C%22stateProv%22%3A%22GA%22%7D%2C%22Name%22%3A%22%22%2C%22Latitude%22%3A%2231.7114886%22%2C%22Longitude%22%3A%22-83.25471970000001%22%2C%22IsPreferred%22%3A%22false%22%7D
I found solution and it's working absolutely correct as i want
$address={
"ID": "0",
"basicAddress": {
"ID": "0",
"Line1": "327 S Main St",
"Line2": "",
"Line3": "",
"City": "Fitzgerald",
"ZipCode": "31750",
"StateProv": "",
"Country": "",
"stateProv": "GA"
},
"Name": "",
"Latitude": "31.7114886",
"Longitude": "-83.25471970000001",
"IsPreferred": "false"
};
cookie_expire_time=30000;
header("Set-Cookie: address=$address; Domain=.example.com;Path=/; Max-Age=".cookie_expire_time.";");
It is correct behaviour for setcookie to URL-encode the value. You can use setrawcookie to avoid that automatic encoding, but then you need to ensure yourself that your cookies are correctly formed to be HTTP compliant.
i'm using PHP and i want to get some date from a json FILE ,
this what i have this file
{
"Contacts": [{
"nataliya.mayk#ut-gr.com": {
"ContactID": "3367870013932183",
"First Name": "",
"Last Name": "maydanyuk",
"Title": "",
"full Name": "maydanyuk",
"Mobile": "",
"num": 0,
"num2": 200
}
}, {
"sebsfsgilbedsdfsdrt045#orsfsefange.fr": {
"ContactID": "336787000013037828",
"First Name": "J\u00e9r\u00f4me",
"Last Name": "Sommet",
"Title": "Directeur Commeqsdqdrcial Retail France, membre du CODIR",
"full Name": "J\u00e9r\u00f4me Sommet",
"Mobile": "",
"num": 6,
"num2": 1600
}
}]
}
so i should first use
$str = file_get_contents('/theFileThatContainsJSON.json');
now i want to access to the the ContactID Of email nataliya.mayk#ut-gr.com , how can i do it ?, i want not to to use loops , because the file will be too big.
i want something like that
echo $str->Contacts->nataliya.mayk#ut-gr.com->ContactID ;
or
echo $str['Contacts']['nataliya.mayk#ut-gr.com']['ContactID'] ;
i tried all of them but not working , as i said before i want to access directly , because i want to get infromations for specific mail .
thanks
this is not working also
why this is not working , i used the same format
$str = file_get_contents('http://freelance-day.eu/zohocontacts.json');
$array = json_decode($str, true);
echo $array['Contacts'][0]['frejus#autoecole-inris.com']['ContactID'];
Try to decode the JSON and structure
$str = file_get_contents('/theFileThatContainsJSON.json');
$str_arr = json_decode($str, true);
echo $str_arr['Contacts']['nataliya.mayk#ut-gr.com']['ContactID']
I am receiving data from a webhook with the following code below.
<?php
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE);
$myfile = fopen("callback.txt", "a") or die("Unable to open file!");
$txt = $input["payload"]["type"];
fwrite($myfile, "\n". $txt);
fclose($myfile);
http_response_code(200);
?>
I am trying to get the 'type' value from the retuned output. I have found that using an if statement inside a for each loop would do the job. However i'm sure this isn't an ideal solution. is there a more direct way of getting that element?
The code above is outputting an empty text file.
and the documentation shows the json should be in the following format:
{
"action": "add",
"collection": "broadcast",
"payload": {
"author": "Sveninge Bambuser",
"created": 1474033783,
"customData": "",
"height": 540,
"id": "9353eaec-794f-11e6-97c0-f19001529702",
"ingestChannel": "cfc8626c-9a0e-ab78-6424-3eb0978d8e45",
"lat": 63.205312,
"length": 0,
"lon": 17.13011,
"positionAccuracy": 25,
"positionType": "GPS",
"preview": "https://archive.bambuser.com/9353eaec-794f-11e6-97c0-f19001529702.jpg",
"resourceUri": "https://cdn.bambuser.net/broadcasts/9353eaec-794f-11e6-97c0-f19001529702?da_signature_method=HMAC-SHA256&da_id=9353eaec-794f-11e6-97c0-f19001529702&da_timestamp=1474033783&da_static=1&da_ttl=0&da_signature=eaf4c9cb29c58b910dcbad17cf7d8a3afa4e6a963624ba4c4fd0bb5bade1cdd6",
"tags": [
{
"text": "whoa"
}
],
"title": "Amazing!",
"type": "live",
"width": 960
},
"eventId": "93df93061a891c23"
}
I replaced:
$txt = $input["payload"]["type"];
with:
$txt = $input['payload']['type'];
it appears to be the double quotes causing the issue.
I got 2 JSON files extracted from the same db,
a:)
{
"hint_data": {
"locations": ["AXQDAP____8AAAAABwAAABEAAAAYAAAAIwIAAERwAgAAAAAADgyCAef7TAMCAAEB", "bOsDAP____8AAAAAAwAAAAcAAADFAQAAFAAAAEJwAgAAAAAANQeCAdzdTAMFAAEB"],
"checksum": 326195011
},
"route_name": ["", ""],
"via_indices": [0, 15],
"via_points": [
[25.299982, 55.376873],
[25.29874, 55.369179]
],
"found_alternative": false,
"route_summary": {
"end_point": "",
"start_point": "",
"total_time": 101,
"total_distance": 871
},
"route_geometry": "{_ego#m}|rhBpBaBvHuC`EuArEUtEtAlDvEnD`MlDvMli#hsEfFzn#QlTgNhwCs#fKwBjF",
"status_message": "Found route between points",
"status": 0
}
b:)
{
"alternative_names": [
["", ""]
],
"route_name": ["", ""],
"status_message": "Found route between points",
"route_geometry": "qo{o#wpslhBmFZwEpBgDzDeBlFWdGv#GCzEyBfIyEtEoNtEuMpAuHkAsCgC[mB{AgCuA{#uCa#}Cl#yBtB}#lDVhEcAtDmCdBcDx#iDDeDk#uBeBeB_CcGcXyFi^{Dg\\wBkP_Fs^wBiS_Ce[_D}UwAcKiBqIgI_TeLaUcMmP_IsHqf#_WyJeE}FMkDjIiTth#y|#loBq^vy#mu#fw#cUxOco#r^gb#zRoOjPsBfMq#rMjBdPnEpKlEnHJ~Dvn#la#nd#pT|f#lLv_#pRzLbHnb#fUxc#lMnaC~zAncBxnAkB|bB|CbmCl]rYxCzkCjwBzoBjxGl_G|fNhcMf~E~mE~pFt}EjbBlzAhvInyHfqDb~CblAw#poAzt#z}#bb#diD~dBxtEjgCfjDljBpuAfw#bpGngDhqF~yC~g#la#v~#ni#rbAjg#jPJlCFNdDGdDu#j#eAhBa#lCLdCaCjI_BtCy#vA_DvF}qAf}Bof#l{#{CnFoKdR}mAxBgM|TkJxPmLlSsf#|}#gf#x#kOzXmEfGmSx^kf#tw#mDtL}k#r~#ykCjjEau#niAee#bu#uUl\\}DpFzCrCr|#dt#|NbLroBx_BdZlV|DbDpBr~Anq#xm#r|#ls#|y#dq#}OXuMQcDhEoBgBeCCu[xXmBH",
"route_summary": {
"end_point": "",
"start_point": "",
"total_time": 824,
"total_distance": 15391
},
"found_alternative": true,
"alternative_summaries": [{
"end_point": "",
"start_point": "",
"total_time": 886,
"total_distance": 14967
}],
"via_points": [
[25.196808, 55.273754],
[25.139168, 55.187702]
],
"status": 0,
"via_indices": [0, 144],
"hint_data": {
"locations": ["TdMLAP____8AAAAADwAAAA8AAAA9AAAAbAAAAOtwBgAAAAAACXmAARxpSwMEAAEB", "4Q4AAGKyBgAAAAAACQAAAAAAAAAhAQAAAAAAAGUYAAAAAAAA4Zd_AfgYSgMGAAEB"],
"checksum": 326195011
},
"alternative_geometries": ["qo{o#wpslhBmFZwEpBgDzDeBlFWdGv#GCzEyBfIyEtEoNtEuMpAuHkAsCgC[mB{AgCuA{#uCa#}Cl#yBtB}#lDVhEcAtDmCdBcDx#iDDeDk#uBeBeB_CcGcXyFi^{Dg\\wBkP_Fs^wBiS_Ce[_D}UwAcKiBqIgI_TeLaUcMmP_IsHqf#_WyJeE}FMkDjIiTth#y|#loBq^vy#ec#vfAyeAfcCok#vtA}Wtx#uS|d#skAvfCgExJgJpTqH|O}#n~#wSve#qEhKkYdp#gB~DuUrk#_JdRsAhDmJlVqd#rcAuM|Zeg#zkAiKzUgIbS}B~EtDvBhr#a#dQ~J|rBpmAj_CfyAlAzD^lDgHnOyQlg#w[l|#}Q~d#eBB}Af#mAdAw#bBWpBJrBn#hBaAjGif#ptAk^rmAoVxy#cHjPmCHE|Bp[xRpc#ZfLvIzLlIreG~cEjrArz#rmAl|#lbDrzBjWlQ|xA~bAho#pc#d_#jWng#j^hNzJvGnEnPjLlAx#lgAhv#bGvCjkBvoAbjDr}BvfAx{#t\\rSfoDviC~zAjgAfOxIvAbAjwCtsBv|#|m#bD|BvLId_Dt|BtLlIxsAx_AfE~Crn#hc#rKvIh_BniApe#z\xIpGtoBpxAtEdDrQrMzjChlB~#lo#nwFpE|jBl|AzFzE|DfDvDrCjKfJr#n\\pLzKnBzzAdO~LhaFxaEzCdCnLpKbp#ti#nIjHdRzMjo#tg#~MvKpwCtdClw#bm#z[bWfr#vk#zCrCr|#dt#|NbLroBx_BdZlV|DbDpBr~Anq#xm#r|#ls#|y#dq#}OXuM`QcDhEoBgBeCCu[xXmBH"],
"alternative_indices": [0, 183]
}
And I am running this script on every JSON file.
Here is the script.
<?php
$json = '{"hint_data":{"locations":["AXQDAP____8AAAAABwAAABEAAAAYAAAAIwIAAERwAgAAAAAADgyCAef7TAMCAAEB","bOsDAP____8AAAAAAwAAAAcAAADFAQAAFAAAAEJwAgAAAAAANQeCAdzdTAMFAAEB"],"checksum":326195011},"route_name":["",""],"via_indices":[0,15],"via_points":[[25.299982,55.376873],[25.29874,55.369179]],"found_alternative":false,"route_summary":{"end_point":"","start_point":"","total_time":101,"total_distance":871},"route_geometry":"{_ego#m}|rhBpBaBvHuC`EuArEUtEtAlDvEnD`MlDvMli#hsEfFzn#QlTgNhwCs#fKwBjF","status_message":"Found route between points","status":0}';
$data = json_decode($json);
$totalTime = $data->route_summary->total_time;
var_dump($totalTime); // DUMPS 101
I am getting the first JSON file output correctly but I am getting an error in the 2nd one.
Please tell me what's wrong with the JSON file.
Your json is not valid.
The "alternative_geometries" property contains a string that is not properly encoded. (\x is not valid. If you want the slash, then it would need to be \\x)
Try validating it somewhere like this: http://jsonlint.com/
1) put data to text file
2) try again with:
<?php
$data = file_get_contents('./relative/path/to/file.json');
$data = json_decode($data);
$totalTime = $data->route_summary->total_time;
var_dump($totalTime);
it would be better to write data to files and put somewhere to download them to check the file.
I want preserve original value of target field and use json_decode to use following string as object:
{
"translatorID": "f4a5876a-3e53-40e2-9032-d99a30d7a6fc",
"label": "ACL",
"creator": "Nathan Schneider",
"target": "^https?://(www[.])?aclweb\\.org/anthology-new/[^#]+",
"minVersion": "1.0.7",
"maxVersion": "",
"priority": 100,
"browserSupport": "gcs",
"inRepository": true,
"translatorType": 4,
"lastUpdated": "2012-01-01 01:42:16"
}
What you can do before parsing with json_decode is:
$string = str_replace('\\', '\\\\\\\\', $string);
var_dump(json_decode($string, true));
This must be a bug in the json parser.
The method is not very clean but at least you're getting your results.
Did you try stripping the slashes off?
This worked for me :
$string = '{
"translatorID": "f4a5876a-3e53-40e2-9032-d99a30d7a6fc",
"label": "ACL",
"creator": "Nathan Schneider",
"target": "^https?://(www[.])?aclweb\.org/anthology-new/[^#]+",
"minVersion": "1.0.7",
"maxVersion": "",
"priority": 100,
"browserSupport": "gcs",
"inRepository": true,
"translatorType": 4,
"lastUpdated": "2012-01-01 01:42:16"
}';
var_dump( json_decode(stripslashes ($string)));