My json data is:
{"jsondata":[[1,7,16,29,41,45],[2,12,21,31,36,45]]}
There are 2 sets of numbers and each set has 6 different number. And the number of total sets can be more according to user's input. So, there may be 3 sets which means 18 numbers, etc. If I copy/paste that in to http://json.parser.online.fr/ , I see no error. So, json data is correct, I guess.
Second, here is my PHP file:
<?php
$input = file_get_contents('php://input');
$result=json_decode($input);
var_dump($result);
?>
That works fine too. I mean, when I run these lines, in the chrome's developer tool, I can see these:
object(stdClass)#1 (1) {
["jsondata"]=>
array(2) {
[0]=>
array(6) {
[0]=>
int(1)
[1]=>
int(7)
[2]=>
int(16)
[3]=>
int(29)
[4]=>
int(41)
[5]=>
int(45)
}
[1]=>
array(6) {
[0]=>
int(2)
[1]=>
int(12)
[2]=>
int(21)
[3]=>
int(31)
[4]=>
int(36)
[5]=>
int(45)
}
}
}
So far, I think, what I have to understand is json data is correct and php can respond it back. So, how can I reach this numbers and assing them into another variable in PHP? My actual aim is send them into the mysql. If I can get them, it is easy.
Some says use key/value pair thing but the problem is, my json data creates itself according to user's input. User clicks some numbers and then the number get appended into the json data. And it continues each of six clicks:
function createjson(){
var c=1;
var json='{"jsondata":[[';
$("#kup td").each(function(){
if($(this).html()!="" && $(this).html()!="SELECTED NUMBERS")
{
json+= parseInt($(this).html())+',';
if($(this).index()%5==0 && $(this).index()!=0) //sixth number selected
{
json=json.substring(0,json.length-1);
json+="],["
}
}
});
json=json.substring(0,json.length-3);
json+="]]}";
return json;
};
I thought I found my answer here but it didn't work either or I did somethings wrong. I am very newbie on these json stuffs, so please don't force me to change whole thing. There must be a way to reach this values. So, please save me guys :-)