Special HTML JSON parsing - php

i've got an JSON String like this:
a: 2: {
s: 4: "unit";
s: 2: "h1";
s: 5: "value";
s: 40: "Mercedes-Benz A 45 AMG / 340 PS / Allrad";
}
Now, I don't know what to do with that because of the weird keys (i think in the 's' that means the length of the string).
If I use it like this nothing can parse it (with php json_decode or with obj-c SBJsonParser).
Is there a way to generate html of that in php or how can i read only the last value?
Thanks in advance

This looks like serialized array, but your string is definitely not valid. (http://php.net/manual/en/function.unserialize.php)

This is not a valid JSON so no json parser would read it, you can treat it as a regular string and use string manipulation to get what you need.
In PHP in order to get the last value:
$str = ...//your json string
$lastValue = substr($str,strripos($str,'s:'));
this should return (according to your sample input): "40: "Mercedes-Benz A 45 AMG / 340 PS / Allrad";"

The above mentioned JSON format is absolutely invalid.
{
"a": {
"2": [
{ "s": { "4": "unit" } },
{ "s": { "2": "h1" } },
{ "s": { "5": "value" } },
{ "s": { "40": "Mercedes-Benz A 45 AMG / 340 PS / Allrad" } }
]
}
}
This would be a valid JSON format

I suggest to treat it as a string for the beginning. Then use string manipulation to get rid of the "a: " and "s: ". Other requests may return other types (if I am right that these letters indicate a data type.)
Then you could try parsing it with a JSON parser.
No guarantee though :) Because I am not qute sure out of the top of my head, whether these numbers are valid JSON or have to be encapsulated in quotation marks.

Related

How to randomize json

I have a randquotes.json file
{
"author": "William Shakespeare",
"quotes": "A brave flea is a flea that can dare to get its breakfast on the lips of a lion."
},
{
"author": "Winston Churchill",
"quotes": "We live with what we get, but we bring life to what we give."
},
{
"author": "Wolfgang von Gothe",
"quotes": "Knowledge is not enough, we must practice it. Intention is not enough, we must do it."
}
Then I want "author" and "quotes" to be generated randomly with php
How?
thanks for help
Assuming you actually have valid a JSON string...
Convert the json to a PHP datatype using json_decode()
find out how large the array is
generate a random number between 0 and array size
Return that array occurance, I did that as a json string again using json_encode()
$json_string = '
[
{
"author": "William Shakespeare",
"quotes": "A brave flea is a flea that can dare to get its breakfast on the lips of a lion."
},
{
"author": "Winston Churchill",
"quotes": "We live with what we get, but we bring life to what we give."
},
{
"author": "Wolfgang von Gothe",
"quotes": "Knowledge is not enough, we must practice it. Intention is not enough, we must do it."
}
]';
$arr = json_decode($json_string);
// How big is the array
$max = count($arr) -1;
$rand_idx = rand(0, $max);
echo json_encode($arr[$rand_idx]);

Valid JSON Results in PHP json_decode Throwing A Syntax Error

Welp, I see quite a few hits on this, but none seem to answer my question.
I have a REST method that returns this JSON:
This is the exact string in the $result variable, below:
{"people":{"people":{"new_user":{"id":7,"name":"Marvin","lang":"en","read_token":1,"write_token":11,"last_access":"2018-06-17 17:00:02","writeable":true,"surname":"Martian","middle_name":"D","given_name":"Marvin","nickname":"Angry Little Fella","payload":"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIyLjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIKCSBpZD0ic3ZnMjczMzMiIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIiB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgoJIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTU2LjggMjE5LjMiCgkgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTU2LjggMjE5LjM7IiB4bWw6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QkJQy01NzkuOCw1OTYuNS01NzkuMyw1OTcuNi01NzguNyw1OTcuNyIvPgoJCTxwYXRoIGlkPSJwYXRoMTAzNzIiIGNsYXNzPSJzdDEiIGQ9Ik0tNTc4LjcsNTk3LjdjMC42LDAsMS4yLTEuMSwxLjMtMi41YzAuMS0xLjQtMC40LTIuNi0xLTIuNmMtMC42LDAtMS4yLDEuMS0xLjMsMi41CgkJCUMtNTc5LjgsNTk2LjUtNTc5LjMsNTk3LjYtNTc4LjcsNTk3Ljd6Ii8+Cgk8L2c+CjwvZz4KPC9zdmc+Cg==","payload_type":"image\/svg+xml;base64","associated_login":{"id":11,"name":"Marvin","lang":"en","login_id":"Marvin","write_token":11,"last_access":"2018-06-17 17:00:02","writeable":true,"user_object_id":7,"security_tokens":[11],"password":"6f2T8rK4"}}}}}
Yeah, it's big and fugly, but it is completely valid.
When I feed it to JSONLint, I get a nice green bar and well-formatted JSON:
{
"people": {
"people": {
"new_user": {
"id": 7,
"name": "Marvin",
"lang": "en",
"read_token": 1,
"write_token": 11,
"last_access": "2018-06-17 16:56:49",
"writeable": true,
"surname": "Martian",
"middle_name": "D",
"given_name": "Marvin",
"nickname": "Angry Little Fella",
"payload": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIyLjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIKCSBpZD0ic3ZnMjczMzMiIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIiB4bWxu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AuMS0xLjQtMC40LTIuNi0xLTIuNmMtMC42LDAtMS4yLDEuMS0xLjMsMi41CgkJCUMtNTcxLjUsNTk2LjQtNTcxLjEsNTk3LjYtNTcwLjQsNTk3LjZ6Ii8+CgkJPHBhdGggaWQ9InBhdGgxMDM2OCIgY2xhc3M9InN0NCIgZD0iTS01NzguNyw1OTcuN2MwLjYsMCwxLjItMS4xLDEuMy0yLjVjMC4xLTEuNC0wLjQtMi42LTEtMi42Yy0wLjYsMC0xLjIsMS4xLTEuMywyLjUKCQkJQy01NzkuOCw1OTYuNS01NzkuMyw1OTcuNi01NzguNyw1OTcuNyIvPgoJCTxwYXRoIGlkPSJwYXRoMTAzNzIiIGNsYXNzPSJzdDEiIGQ9Ik0tNTc4LjcsNTk3LjdjMC42LDAsMS4yLTEuMSwxLjMtMi41YzAuMS0xLjQtMC40LTIuNi0xLTIuNmMtMC42LDAtMS4yLDEuMS0xLjMsMi41CgkJCUMtNTc5LjgsNTk2LjUtNTc5LjMsNTk3LjYtNTc4LjcsNTk3Ljd6Ii8+Cgk8L2c+CjwvZz4KPC9zdmc+Cg==",
"payload_type": "image\/svg+xml;base64",
"associated_login": {
"id": 11,
"name": "Marvin",
"lang": "en",
"login_id": "Marvin",
"write_token": 11,
"last_access": "2018-06-17 16:56:49",
"writeable": true,
"user_object_id": 7,
"security_tokens": [11],
"password": "TuqWG+%y"
}
}
}
}
}
Nevertheless, feeding this JSON to PHP 7.2.1's json_decode() function keeps returning a JSON_ERROR_SYNTAX error (bad syntax).
I think the issue may be with the data in the SVG file, but that is valid Base64 data. It should be fine in JSON.
I tried all the various solutions mentioned in other posts, but still no dice.
Any ideas?
UPDATE: Here's the PHP code that I run it through:
echo('RESULT:<pre>');
var_dump(json_decode($result));
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
echo('</pre>');
That code, in my server/laptop, is what's exposing it.
UPDATE 2: This is the dump from my cURL routine, showing the response:
string(10159) "HTTP/1.1 200 OK
Date: Sun, 17 Jun 2018 17:29:35 GMT
Server: Apache
X-Powered-By: PHP/7.2.1
Content-Length: 10007
Content-Type: application/json
{"people":{"people":{"new_user":{"id":7,"name":"Marvin","lang":"en","read_token":1,"write_token":11,"last_access":"2018-06-17 17:29:35","writeable":true,"surname":"Martian","middle_name":"D","given_name":"Marvin","nickname":"Angry Little Fella","payload":"<REMOVED FOR BREVITY>","payload_type":"image\/svg+xml;base64","associated_login":{"id":11,"name":"Marvin","lang":"en","login_id":"Marvin","write_token":11,"last_access":"2018-06-17 17:29:35","writeable":true,"user_object_id":7,"security_tokens":[11],"password":"1Jq6$oT0"}}}}}"
OK. I wanted to let y'all know what happened. It ain't an answer, but it will be the one I greencheck.
I took off and nuked it from orbit, and now it works.
I have to assume that I did something that sent invisible characters that didn't make it into copy and paste, so the JSONLint never saw them. I'll bet if I had cURLed or wgetted straight from the test harness, it would have borked.
This is a warning to me: Don't get too feisty with the CLI. I'm maybe not as hot at this stuff as I'd like to think.
Thanks for the help, folks.

Changing string names from a list

Doing this in PHP
I have users input an abbreviation for a city, that gets saved as a string, for example:
ANA
BOS
VAN
These stand for: Anaheim Boston Vancouver
I want it so that when I get the input/string, it changes the string name to it's full name.
ANA -> Anaheim
BOS -> Boston
VAN -> Vancouver
What is the best way to go about this? Thank you all, greatly appreciated.
Peut22's answer ist working, but i think it is better to store the pairs in an array to be more eaily maintainable. You could also get this array from a database or config file.
$names = array(
"ANA" => "Anaheim",
"BOS" => "Boston",
"VAN" => "Vancouver",
);
if(array_key_exists((string)$userinput, $names)) {
echo $names[$userinput];
} else {
echo "invalid";
}
update: fixed, so there is no "undefined index" - notice in case you got such a low error_reportinglevel set:
$names["ANA"] = "Anaheim";
$names["BOS"] = "Boston";
$names["VAN"] = "Vancouver";
function getFullName($input, $names)
{
//turning all input into upper case letters:
$input = strtoupper($input);
//making sure input is maximum 3 characters long:
$input = substr($input, 0, 3);
if(!array_key_exists($input, $names))
{
return "*ERROR: Unknown City Abbreviation*";
}
else
{
return $names[$input];
}
}
//usage:
$user_input = "bos";
echo getFullName($user_input, $names);
I think you would get a good result by using a switch, which returns the full name if you happend to get an abbreviation, of the full input string if the name is not recognized.
An example in pseudo code would be:
Switch string
case "ANA" : string = "Anaheim"
case "BOS" : string = "boston"
end
EDIT: if you're using php, the code would then look like :
switch ($i) {
case "ANA":
$i="anaheim"
break;
case "BOS":
$i="boston"
break;
}

How to get JSON Strings Difference Percentage

Is there any logic/algorithm to compare the two JSON strings with difference percentage. I'm trying to use it to validate the signature which I'm storing as JSON strings.
String 1:
[
{"lx":5,"ly":34,"mx":5,"my":33},
{"lx":5,"ly":34,"mx":5,"my":34},
{"lx":6,"ly":32,"mx":5,"my":34},
{"lx":7,"ly":31,"mx":6,"my":32},
{"lx":8,"ly":31,"mx":7,"my":31},
{"lx":9,"ly":30,"mx":8,"my":31},
{"lx":10,"ly":29,"mx":9,"my":30},
{"lx":11,"ly":29,"mx":10,"my":29},
{"lx":11,"ly":28,"mx":11,"my":29}
]
String 2:
[
{"lx":5,"ly":33,"mx":5,"my":32},
{"lx":5,"ly":33,"mx":5,"my":33},
{"lx":6,"ly":32,"mx":5,"my":33},
{"lx":7,"ly":32,"mx":6,"my":32},
{"lx":8,"ly":32,"mx":7,"my":32},
{"lx":9,"ly":32,"mx":8,"my":32},
{"lx":10,"ly":31,"mx":9,"my":32},
{"lx":11,"ly":30,"mx":10,"my":31},
{"lx":12,"ly":30,"mx":11,"my":30},
{"lx":13,"ly":29,"mx":12,"my":30}
]
Any suggestion would be highly appreciated.
I didn't get exactly what you want to do, but if you just want to check string similarity you can use similar_text php command
Sample :
$str1 = '{"lx":5,"ly":34,"mx":5,"my":33},
{"lx":5,"ly":34,"mx":5,"my":34},
{"lx":6,"ly":32,"mx":5,"my":34},
{"lx":7,"ly":31,"mx":6,"my":32},
{"lx":8,"ly":31,"mx":7,"my":31},
{"lx":9,"ly":30,"mx":8,"my":31},
{"lx":10,"ly":29,"mx":9,"my":30},
{"lx":11,"ly":29,"mx":10,"my":29},
{"lx":11,"ly":28,"mx":11,"my":29}';
$str2 = '{"lx":5,"ly":33,"mx":5,"my":32},
{"lx":5,"ly":33,"mx":5,"my":33},
{"lx":6,"ly":32,"mx":5,"my":33},
{"lx":7,"ly":32,"mx":6,"my":32},
{"lx":8,"ly":32,"mx":7,"my":32},
{"lx":9,"ly":32,"mx":8,"my":32},
{"lx":10,"ly":31,"mx":9,"my":32},
{"lx":11,"ly":30,"mx":10,"my":31},
{"lx":12,"ly":30,"mx":11,"my":30},
{"lx":13,"ly":29,"mx":12,"my":30}';
$percent = 0;
echo similar_text($str1,$str2,$percent).' equal chars'.PHP_EOL;
echo $percent.'% similarity';
Gives you :
269 equal chars
78.425655976676% similarity
String distance can be calculated with the levenshtein function
Too bad it is limited to strings no longer than 255 characters.

Is there a maximum length for json in Java?

I'm getting an output of the classes that students saw through all the university career.
this is an example of the output
{
"HISTORICOP": [
{
"MATERIA": "PROCESOS DEL LENGUAJE ",
"NOTA": "7 ",
"ANIO": "2000",
"PERIODO": "001",
"ENEMENOSUNO": "0 "
},
{
"MATERIA": "RAZONAMIENTO BASICO FG ",
"NOTA": "13 ",
"ANIO": "2000",
"PERIODO": "001",
"ENEMENOSUNO": "0 "
},
{
"MATERIA": "DESARROLLO DE COMPETENCIAS ",
"NOTA": "8 ",
"ANIO": "2000",
"PERIODO": "001",
"ENEMENOSUNO": "n-1 "
}
]
}
these are 3 of the results
but the whole output are 91 results,
when I run it on a emulator the blackberry is not able to read it
but when I try with less results he can read it!
Is there a maximum json length size so it can be read in java?
this is how I retrieve the info! from SAP
try {
$conn = new sapnwrfc($config);
$fds = $conn->function_lookup("ZCM_GET_HORARIO");
$parms = array('CEDULA' => '16814224');
$results = $fds->invoke($parms);
echo "[".json_encode($results)."]";
$conn->close();
} catch (Exception $e) {
echo "Connection Failed 3";
}
There is no absolute limitation in JSON. In Java there is a limit to the length of a String, which is 2^31-1 or over 2 billion characters long. But given the snippet of code you showed us you are not actually using Java (Java doesn't have "$" before variable names).
There may be a limitation in whatever library you are using which is not a fundamental limitation of the data format or the language.
But if you are having problems with just 91 items (not 91 thousand or 91 million) then it is far more likely that you problem is NOT due to a fundamental size limitation. If you post more about what actual errors you saw you might get a more useful response.

Categories