for save the user - http://aeps.gear.host/api/Test/SaveUser
INPUT
{
"Name": "sample",
"EmailId": "sample#gmail.com",
"MobileNo": "9876543210",
"Gender": "MALE",
"Latitude": "99.99",
"Longitude": "99.99",
"Birthdate": "05-03-2017"
}
OUTPUT
{
"$id": "1",
"Status": true,
"Data": "[{}]",
"Message": "Details saved successfully"
}
for get user
2) http://aeps.gear.host/api/Test/GetDetails
INPUT
{
"RegistrationId": "0"
}
OUTPUT
{
"$id": "1",
"Status": true,
"Data": [
{
"$id": "2",
"RegistrationId": 1,
"Name": "sample string 1",
"EmailId": "sample string 2",
"MobileNo": "sample string 3",
"Gender": "sample string 4",
"Latitude": "sample string 6",
"Longitude": "01-01-1900",
"Birthdate": "sample string 5"
}
],
"Message": "List generated successfully"
}
I want to Register the user details in registration screen and show all registered users in view user screen in android. I have a URL for get and post both with json response.
I want the user to register with name, mail , number and want to show in a simple list in next screen
Related
I have a JSON response that I get from the server like below
{
"questionList": [{
"qno": "1",
"state_name": "State1",
"category_name": "Category1",
"question_type": "type1",
"question": "This is question 11",
"options": ["No", "yes "]
},
{
"qno": "2",
"state_name": "State1",
"category_name": "Category1",
"question_type": "type1",
"question": "This is question12",
"options": ["No", "yes "]
},
{
"qno": "3",
"state_name": "State1",
"category_name": "Category2",
"question_type": "type2",
"question": "This is question 21",
"options": ["No ", "yes "]
},
{
"qno": "4",
"state_name": "State1",
"category_name": "Category3",
"question_type": "type1",
"question": "This is question 31",
"options": ["No ", "yes "]
},
{
"qno": "5",
"state_name": "State1",
"category_name": "Category3",
"question_type": "type1",
"question": "This is question 32",
"options": ["No ", "yes "]
}
]
}
Now I want to restructure it based on category so that questions with multiple same categories will fall under a single category and also few of my own variables. Below is a sample output of how it should look like.
[
{
"state": "State1",
"category": "Category1",
"questions": [
{
"questionID": "1",
"question": "This is question 11",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
},
{
"questionID": "2",
"question": "This is question12",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
}
]
},
{
"state": "State1",
"category": "Category2",
"questions": [
{
"questionID": "3",
"question": "This is question 21",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type2"
}
]
},
{
"state": "State1",
"category": "Category3",
"questions": [
{
"questionID": "4",
"question": "This is question 31",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
},
{
"questionID": "5",
"question": "This is question 32",
"options": ["No ", "yes "],
"status": 0,
"files": [],
"questionType": "type1"
}
]
}
]
I'm not really an expert in JSON operations. Could anyone tell me shat should be the best way to solve this?
So if we take the questionList array from the json that you provided we can do the following.
Loop over each question in the questionList array.
Convert the question to the new format.
Check to see if we have come across the category before.
If we have not, we are going to create the category, add the new question to it, and add the category to our results array.
If we have found the category before then we are going to find it in the results array and add the new question to it.
Here is the code
let data = [{qno: "1", state_name: "State1", ... }, ... ] // notice that this is the questionList array and not an object
let categories = []; // to track the categories that you have found
let result = []; // where your results will be stored
data.forEach(question => {
// create the question
let newQuestion = {};
newQuestion.questionID = question.qno;
newQuestion.question = question.question;
newQuestion.options = question.options;
newQuestion.status = 0;
newQuestion.files = [];
newQuestion.questionType = question.question_type;
// check to see if we have the category, if not create it
if (categories.indexOf(question.category_name) === -1) {
// create a new category
let newCategory = {};
newCategory.state = question.state_name;
newCategory.category = question.category_name;
newCategory.questions = [];
newCategory.questions.push(newQuestion); // add the question to the category we just created
result.push(newCategory); // add the category to the result
categories.push(question.category_name); // track the category so we know not to create a new one
} else {
// search for the category
let foundCategory = result.filter(group => group.category === question.category_name);
// if we have found a category add the new question to it
if (foundCategory.length) {
foundCategory[0].questions.push(newQuestion);
}
}
});
console.log(result);
I want to know how to filter data. I got data with category name but cannot filter category wise.Here is my data:
{
"TITLE": "tea",
"PRICE": "17",
"QTY": "1",
"CAT_ID": "33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg"
},
{
"TITLE": "Coffee",
"PRICE": "102",
"QTY": "1 ",
"CAT_ID": "8",
"CAT_NAME": "MORNING SPECIAL",
"TYPE": "veg"
},
{
"TITLE": "Jeera chachh",
"PRICE": "42",
"QTY": "1",
"CAT_ID": "33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg"
},
{
"TITLE": "Roti Ghee Wali",
"PRICE": "21",
"QTY": "1",
"CAT_ID": "33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg"
},
{
"TITLE": "Paneer paratha",
"PRICE": "102",
"QTY": "1 ",
"CAT_ID": "8",
"CAT_NAME": "MORNING SPECIAL",
"TYPE": "veg"
},
{
"TITLE": "Mix paratha",
"PRICE": "102",
"QTY": "1",
"CAT_ID": "8",
"CAT_NAME": "MORNING SPECIAL",
"TYPE": "veg"
},
I already parse the data but not able to set in fragment according to category.Can anyone solve my issue.
Step 1: Store the data in database.
Step 2: Search
select * from table where CAT_NAME = 'your_filter_category'.
or better ....CAT_NAME like %your_filter_category%.
In Case of no database;
Store the Data in list.
HashMap<String, ArrayList<Item>> map = new HashMap<>();
ArrayList<Item> itemList = new ArrayList<>();
Loop on List{
Item item = fromLoop index;
if(map.contains(item.getCat())){
itemList = map.get(item.getCat());
itemList.put(item);
map.put(item.getCat(),itemList);
}else{
itemList.clear();
itemList.put(item);
map.put(item.getCat(),itemList);
}
}
//after loop you will get HashMap with keys as categories and Values as the list of selected key category.
Step 3: Publish the results.
Note: No one will do your homework here. the only thing we can do for you, we can assist you how to do.
enter your code to: JSON Formatter and you will see that something is invalid in your JSON, it has multiple root elements. Maybe you should store whole code in JSONArray like this: `
{
"features":
[{
"TITLE": "tea",
"PRICE": "17",
"QTY": "1",
"CAT_ID":"33",
"CAT_NAME": "POPULAR PRODUCTS",
"TYPE": "veg" },
{
"TITLE":"Coffee",
"PRICE": "102",
"QTY": "1 ",
"CAT_ID": "8",
"CAT_NAME":"MORNING SPECIAL",
"TYPE": "veg"
}]
}
I have this json
{
"results": [{
"gender": "male",
"name": {
"title": "mr",
"first": "isidro",
"last": "nogueira"
},
"location": {
"street": "3663 rua amazonas ",
"city": "mesquita",
"state": "rio de janeiro",
"postcode": 27744
},
"email": "isidro.nogueira#example.com",
"login": {
"username": "orangegoose315",
"password": "redalert",
"salt": "Dd3U7U03",
"md5": "325f1e8753222facba6ee63a5e2451de",
"sha1": "a63a0c544a956e235330b0ed76d11d3ad17c7979",
"sha256": "ddf18ffff89684617b2c7b8c5c175b9570cb6005916d9b4f3face802bd4f13a1"
},
"dob": "1967-04-23 04:58:32",
"registered": "2016-05-08 01:56:44",
"phone": "(11) 8368-8583",
"cell": "(17) 9743-3074",
"id": {
"name": "",
"value": null
},
"picture": {
"large": "https://randomuser.me/api/portraits/men/57.jpg",
"medium": "https://randomuser.me/api/portraits/med/men/57.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/men/57.jpg"
},
"nat": "BR"
}],
"info": {
"seed": "5b3dff5c25caaf7f",
"results": 1,
"page": 1,
"version": "1.1"
}
}
This data is of just one user. I have 50 of them.
I am still in learning stage and what I have done is that I have successfully listed all user in an activity. Now what I want to do is when I click on a user it should show it's related details in next activity...
List Users->Select Users->Show selected user details
I still don't know how to send data to other activity and display it.
I want to know that how can i fetch data through j sons. I.I am creating like this but did not get any data?
"arr": [1]
0: {
"obj": {
"id": "24"
"dispensary_id": "24"
"item_name": "item 3"
"total_feedback": "1"
"total_item": "13"
"followers": "7"
"follow_status": "following"
"category": "Edibles"
"strain": "Indica"
"tch": "0.70"
"cbd": "13.30"
"description": "testing items"
"image": "1447508911_greenfeed-3.jpg"
"qty1": "1/8 OZ"
"price1": "100"
"qty2": "1/4 OZ"
"price2": "200"
"qty3": "1/2 OZ"
"price3": "400"
"qty4": "1 OZ"
"price4": "799"
"dispensary_first_name": "Acme Dispensary"
"dispensary_last_name": "Smith"
"company": "Acme Dispensary"
"dispensary_image": "1449182412.png"
"city": "Irvine"
"state": "CA"
"status": "1"
}-
}-
-
"result": "true"
}
Use gson library for parsing JSON data. To learn how to use it go through with this link http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html
your JOSN format is wrong it should be like this
{
"obj": {
"id": "24",
"dispensary_id": "24",
"item_name": "item 3",
"total_feedback": "1",
"total_item": "13",
"followers": "7",
"follow_status": "following",
"category": "Edibles",
"strain": "Indica",
"tch": "0.70",
"cbd": "13.30",
"description": "testing items",
"image": "1447508911_greenfeed-3.jpg",
"qty1": "1/8 OZ",
"price1": "100",
"qty2": "1/4 OZ",
"price2": "200",
"qty3": "1/2 OZ",
"price3": "400",
"qty4": "1 OZ",
"price4": "799",
"dispensary_first_name": "Acme Dispensary",
"dispensary_last_name": "Smith",
"company": "Acme Dispensary",
"dispensary_image": "1449182412.png",
"city": "Irvine",
"state": "CA",
"status": "1"
}
}
for this you can check on whether your json is valid or not http://jsonlint.com/
for creating json you can use some library like
JSONObject jsonObject = new JSONObject();
jsonObject.add("key", "value");
jsonObject.add("key", "value");
I'm having an array of objects represented as JSON string that will be coming from an API server. Let's suppose we have some Movie Categories and actual Movies that belong to each category:
[
{
"id": "1",
"name": "Action",
"movies": [
{
"id": "1",
"name": "Movie 1",
"description": "Movie 1 Description",
"other": "Other..."
},
{
"id": "2",
"name": "Movie 2",
"description": "Movie 2 Description",
"other": "Other..."
}
]
},
{
"id": "2",
"name": "Drama",
"movies": [
{
"id": "3",
"name": "Movie 3",
"description": "Movie 3 Description",
"other": "Other..."
},
{
"id": "4",
"name": "Movie 4",
"description": "Movie 4 Description",
"other": "Other..."
}
]
}
]
The users of my android app will need to be able to browse through categories/movies.
Which of the following scenarios is better regarding the performance of the code and optimal memory usage?
Assume that there will be many channels and categories.
1. Parse the JSON string once, create ArrayLists of Category and Movie objects for each category that I will later use them for populating lists.
2. Create a Parser with few methods like get_total_channels, get_channel, get_category that will always parse the contents of the JSON string to return me the appropriate data to populate the lists.
3. Any other suggestion?