I am a novice developer and I am stuck here since last few days. I am using jQuery query builder parser for laravel by timgws and sending the form data by Ajax. I can get the query in the controller but I want to access the JSON data before making the query. I was following this reference but i can't access the data even after json_decode() with "true" argument. Here is the data I receive in the controller:
{
"condition": "AND",
"rules": [
{
"id": "diseases",
"field": "mesh_id",
"type": "string",
"input": "select",
"operator": "equal",
"value": "C535575"
}
],
"valid": true
}
How can I access this value/type/fields from this data?
Related
I'm getting a JSON response from an API provider which I can't change, and there are lots of nested objects in the response and then there is an object which I need, below is just the example of response actual response has a lot of nested objects and then the match object,
I can easily access the match object but in some case, the API provider add some more object above it as shown in the 2nd response where he added the group and then there is match object which I need,
still by using some if, else we can get through it.
but are there any methods or ways available that can directly give me access to the match object or can find the match object?
I'm using laravel 5.8
and tried some of the collection methods none of them work on objects.
in actual response, I have to go 7 steps nested.
//1nd API response
[{
"version": "2.258.2",
"sport": "badminton",
"lang": "en",
"generated_utc": "2021-07-28T13:58:16+00:00",
"method": {
"method_id": "258",
"name": "get_matches"
"match" : {
score_a:0,
score_b:1
}
}
}]
//2nd API response
[{
"version": "2.258.2",
"sport": "badminton",
"lang": "en",
"generated_utc": "2021-07-28T13:58:16+00:00",
"method": {
"method_id": "258",
"name": "get_matches"
"group":{
"match" : {
score_a:0,
score_b:1
}
}
}
}]
Thank You!
I am getting json array after getting applying query logic.
[
{
"id": "3",
"diag_name": "LT Diagnostics",
"test_name": "Alk PO4",
"booking_date": "2018-05-20"
},
{
"id": "3",
"diag_name": "LT Diagnostics",
"test_name": "CRP",
"booking_date": "2018-05-20"
},
{
"id": "4",
"diag_name": "Seepz Diagnostics",
"test_name": "Alk PO4",
"booking_date": "2018-05-21"
}
]
But i want a more justified json array written below.
[
{
"diag_name": "LT Diagnostics",
"test_name": [
{
"id": "3",
"name" : "Alk PO4"
},
{
"id": "3",
"name" : "CRP"
}
],
"booking_date": "2018-05-20"
},
{
"diag_name": "Seepz Diagnostics",
"test_name": [
{
"id": "4",
"name" : "Alk PO4"
}
],
"booking_date": "2018-05-21"
},
]
I am not getting it,How to do in php. I want a more consolidate json format.
Have you tried changing your SQL query to group by diag_name and booking_date? That would be the first step I’d employ to get the outer data.
Formatting the data in the nested manner you’re after could be a function of whatever record serializer you’re using — does it support nested JSON as a return type, or only flat JSON as your example return value shows?
If the record set -> JSON serializer only ever returns flat data, the comments above are correct that you will have to write your own formatter to change the shape of the JSON yourself...
The accepted answer of this other question may be of help:
Create multi-level JSON with PHP and MySQL
I'm not a PHP guy but this is a typical scenario to use functional programming by means of the monad Map.
Looking online I've found this article that could help you.
Changing datasource output is not always (seldom indeed) a viable option.
Enjoy coding
I am using the cakephp 3.5 to create the REST APIs. I have create an controller and method inside controller when i post the data to controller using POST MEN tools. it returning me an unexpected response
Below is the json array that i am trying use in post data
{
"type": true,
"userRole": "customer",
"signupType": "test",
"userProfile": {
"email": "admin#test.com",
"password": "YLhdh3UfH/oqppQ/P4wUBw==",
"first_name": "admin",
"last_name": "admin",
"phone_no": "admin",
"profile_image": "test.jpg",
"street_address": "test address",
"state": "Chandigarh",
"city": "Chandigarh",
"zipcode": "160022",
"latitude": "30.723306",
"longitude": "76.766114",
"rating": "5",
"role": "customer",
"status": "1"
}
}
And Here is the data that i m getting inside method :-
Array
(
[{"type":"true","userRole":"customer","signupType":"gojus","userProfile":{"email":"admin#gojus_com","password":"YLhdh3UfH/oqppQ/P4wUBw] => =","first_name":"admin","last_name":"admin","phone_no":"admin","profile_image":"test.jpg","street_address":"test address","state":"Chandigarh","city":"Chandigarh","zipcode":"160022","latitude":"30.723306","longitude":"76.766114","rating":"5","role":"customer","status":"1"}}
)
This is the issues inside get data that i am getting "[{" how can i resolve the issues in cakephp 3.5
Read the Manual: XML or JSON Data
Applications employing REST often exchange data in non-URL-encoded
post bodies. You can read input data in any format using
Http\ServerRequest::input(). By providing a decoding function, you can
receive the content in a deserialized format:
// Get JSON encoded data submitted to a PUT/POST action
$jsonData = $this->request->input('json_decode');
I am using "slim-json-api" in a project to access some data in a MySQL database. I am trying to pull back a single row and return this to the response, but I am getting no data back.
$app->get('/topics/:id', function($id) use ($app) {
$topic = ORM::for_table('topics')->find_one($id);
$posts = ORM::for_table('posts')->where('topics_id', $id)->find_array();
$app->render(200, array(
"topic" => $topic,
"posts" => $posts
));
});
The result of this is as follows:
{
"topic": {},
"posts": [
{
"id": "1",
"user_id": "1",
"topics_id": "1",
"post_time": "2014-03-17 12:44:24",
"post_subject": "I like this!",
"post_text": "This is the body of an amazing post!"
}
],
"error": false,
"status": 200
}
The annoying this about this is that I get a fully populated "posts" object and I know the data is present and correct in the DB. It is as if the array of results for "posts" is not an array of single returned value types.
Any help would be much appreciated.
I've search Stack Overflow and Google for an answer but not luck. I'm trying to get the value of each of the locale with php in the following sample (facebook graph api). Any help would be appreciated.
"data": [
{
"id": "123456789/insights/page_fans_locale/lifetime",
"name": "page_fans_locale",
"period": "lifetime",
"values": [
{
"value": {
"en_US": 33975,
"fr_CA": 6906,
"fr_FR": 6105,
"en_GB": 5647
},
"end_time": "2012-03-14T07:00:00+0000"
},
{
"value": {
"en_US": 33992,
"fr_CA": 6906,
"fr_FR": 6107,
"en_GB": 5648
},
"end_time": "2012-03-15T07:00:00+0000"
},
}
First, this fragment is broken. data is a array not a JavaScript object.
Take the correct fragment and analyze data correctly. The best option is:
json_decode();
Here is how to use it.