Send two string and one array inine json with php

hi i wana send some thing like this
{"code:"204,"numposts:"36,"posts":[{"id":"1","title":"title","content":"content is this bro","lat":"12","longt":"11","date":"2015-11-18 17:38:15","file":"","type":"","size":"0"},{"id":"2","title":"","content":"","lat":"","longt":"","date":"2015-11-18 20:23:55","file":"","type":"","size":"0"},{"id":"3","title":"","content":"","lat":"","longt":"","date":"2015-11-19 11:13:16","file":"","type":"","size":"0"},{"id":"4","title":"test","content":"description test","lat":"27.824132","longt":"52.355406","date":"2015-11-20 17:55:27","file":"","type":"","size":"0"},{"id":"5","title":"test","content":"test","lat":"27.824076","longt":"52.355446","date":"2015-11-20 17:56:54","file":"","type":"","size":"0"}]}

with json…how i can create one json with this format?

i have string="“code:“204,” and string=”,"numposts:“36” and array=“posts”…3 thing in one json,whats your points?

Hi,

json_encode() is what you’re looking for

1 Like

thanks for your replay,but i knew json encode, i wana know how send this json with json-encode()??

send 1 string and one array in one json…its possible?

Send to… where?

If you want to encode multiple variables, combine them into array:

$string1 = "foo";
$string2 = "bar";
$array = [1, 2, 3];

$json = json_encode([
    's1' => $string1,
    's2' => $string2,
    'arr' => $array
]);

That will produce:

{"s1":"foo","s2":"bar","arr":[1,2,3]}

1 Like

android app,

This is too general answer. Provide more details of your task to make it clearer for us

1 Like

[quote=“megazoid, post:6, topic:213681”]
This is too general answer. Provide more details of your task to make it clearer for us
[/quote]

for parse json in my java class, first catch code then iknow db is connect or not,then catch numpost to know how much post we have to recive in android app,then we catch post content with post array that located in json,

i think this code is my sulotion,

i ll try this one,

thanks for your valuable time

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.