How to update dynamic editext values into nested json array in android?How do save an Android Activity state using save instance state?How to check if a service is running on Android?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?How do I display an alert dialog on Android?How do I rotate the Android emulator display?How to get the build/version number of your Android application?Loading JSON from String into JSONArray on AndroidHow to manage startActivityForResult on Android?Json Error when parsing as object rather than array :getJSONObject (java.lang.String) in JSONObject cannot be applied to (int)
Should one buy new hardware after a system compromise?
The art of clickbait captions
USPS Back Room - Trespassing?
What is a fully qualified name?
Alternatives to achieve certain output format
Why are GND pads often only connected by four traces?
Where have Brexit voters gone?
Why does Mjolnir fall down in Age of Ultron but not in Endgame?
Is the Unsullied name meant to be ironic? How did it come to be?
How to politely tell someone they did not hit "reply to all" in an email?
Why does this if-statement combining assignment and an equality check return true?
How to attach cable mounting points to a bicycle frame?
Apt - strange requests to d16r8ew072anqo.cloudfront.net:80
When the Torah was almost lost and one (or several) Rabbis saved it?
Best material to absorb as much light as possible
What does $!# mean in Shell scripting?
Popcorn is the only acceptable snack to consume while watching a movie
Why didn't Thanos use the Time Stone to stop the Avengers' plan?
NIntegrate doesn't evaluate
Have 1.5% of all nuclear reactors ever built melted down?
My employer faked my resume to acquire projects
Is it true that cut time means "play twice as fast as written"?
Why were helmets and other body armour not commonplace in the 1800s?
In general, would I need to season a meat when making a sauce?
How to update dynamic editext values into nested json array in android?
How do save an Android Activity state using save instance state?How to check if a service is running on Android?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?How do I display an alert dialog on Android?How do I rotate the Android emulator display?How to get the build/version number of your Android application?Loading JSON from String into JSONArray on AndroidHow to manage startActivityForResult on Android?Json Error when parsing as object rather than array :getJSONObject (java.lang.String) in JSONObject cannot be applied to (int)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This is my json data I have created ui design using this json string but by the time of updating I am confused about this how to correctly get EditText
values and how to update
"SingleExtras": [
"Id": 1,
"name": "size",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "Gb39Rpmdl9",
"extraName": "Small",
"extraPrice": 15,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 30,
"objId": "kknwBtS9zJ",
"extraName": "Medium",
"extraPrice": 18,
"currency": "Aed",
"isEnabled": 0
,
"extraId": 30,
"objId": "d5YfEGAgMt",
"extraName": "Large",
"extraPrice": 20,
"currency": "Aed",
"isEnabled": 1
]
,
"Id": 5,
"name": "Milk",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "8obBCWDXbh",
"extraName": "LowFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 31,
"objId": "CC629INXuP",
"extraName": "FullFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
]
],
"Extras": [
"extraId": 5,
"objId": "PxDQX3LGU2",
"extraName": "ExtraShot",
"extraPrice": 5,
"currency": "Aed",
"isEnabled": 1
]
I'm using the code below to get the modified EditText
values in that
for(int i=0; i < allEds.size(); i++)
pricelist.add(allEds.get(i).getText().toString().trim());
priceidslist.add(allEds.get(i).getId());
This is nested array function here in loop I'm getting array index0,1,2,0,1,2,0 like this i have all editetxt prices list by using im not able to update index position values mismatching
public void jsonarray(JSONArray arry)
try
for (int j = 0; j < arry.length(); j++)
JSONObject rw = arry.getJSONObject(j);
String extraId = rw.optString("extraId");
String objId = rw.optString("objId");
String extraName = rw.optString("extraName");
String extraPrice = rw.optString("extraPrice");
String currenc = rw.optString("currency");
String chksts = rw.optString("isEnabled");
if (namechklist.contains(extraName))
rw.put("isEnabled", "1");
if (nameunchklist.contains(extraName))
rw.put("isEnabled", "0");
if(allnames.contains(extraName))
rw.put("extraPrice", pricelist.get(j));
Log.d("res", "jsonarray:loop "+arry.toString());
Log.d("res", "jsonarray: "+arry.toString());
catch (JSONException e)
e.printStackTrace();
Anyone please suggest me which way is better to achieve this logic correctly
android
add a comment |
This is my json data I have created ui design using this json string but by the time of updating I am confused about this how to correctly get EditText
values and how to update
"SingleExtras": [
"Id": 1,
"name": "size",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "Gb39Rpmdl9",
"extraName": "Small",
"extraPrice": 15,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 30,
"objId": "kknwBtS9zJ",
"extraName": "Medium",
"extraPrice": 18,
"currency": "Aed",
"isEnabled": 0
,
"extraId": 30,
"objId": "d5YfEGAgMt",
"extraName": "Large",
"extraPrice": 20,
"currency": "Aed",
"isEnabled": 1
]
,
"Id": 5,
"name": "Milk",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "8obBCWDXbh",
"extraName": "LowFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 31,
"objId": "CC629INXuP",
"extraName": "FullFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
]
],
"Extras": [
"extraId": 5,
"objId": "PxDQX3LGU2",
"extraName": "ExtraShot",
"extraPrice": 5,
"currency": "Aed",
"isEnabled": 1
]
I'm using the code below to get the modified EditText
values in that
for(int i=0; i < allEds.size(); i++)
pricelist.add(allEds.get(i).getText().toString().trim());
priceidslist.add(allEds.get(i).getId());
This is nested array function here in loop I'm getting array index0,1,2,0,1,2,0 like this i have all editetxt prices list by using im not able to update index position values mismatching
public void jsonarray(JSONArray arry)
try
for (int j = 0; j < arry.length(); j++)
JSONObject rw = arry.getJSONObject(j);
String extraId = rw.optString("extraId");
String objId = rw.optString("objId");
String extraName = rw.optString("extraName");
String extraPrice = rw.optString("extraPrice");
String currenc = rw.optString("currency");
String chksts = rw.optString("isEnabled");
if (namechklist.contains(extraName))
rw.put("isEnabled", "1");
if (nameunchklist.contains(extraName))
rw.put("isEnabled", "0");
if(allnames.contains(extraName))
rw.put("extraPrice", pricelist.get(j));
Log.d("res", "jsonarray:loop "+arry.toString());
Log.d("res", "jsonarray: "+arry.toString());
catch (JSONException e)
e.printStackTrace();
Anyone please suggest me which way is better to achieve this logic correctly
android
add a comment |
This is my json data I have created ui design using this json string but by the time of updating I am confused about this how to correctly get EditText
values and how to update
"SingleExtras": [
"Id": 1,
"name": "size",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "Gb39Rpmdl9",
"extraName": "Small",
"extraPrice": 15,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 30,
"objId": "kknwBtS9zJ",
"extraName": "Medium",
"extraPrice": 18,
"currency": "Aed",
"isEnabled": 0
,
"extraId": 30,
"objId": "d5YfEGAgMt",
"extraName": "Large",
"extraPrice": 20,
"currency": "Aed",
"isEnabled": 1
]
,
"Id": 5,
"name": "Milk",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "8obBCWDXbh",
"extraName": "LowFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 31,
"objId": "CC629INXuP",
"extraName": "FullFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
]
],
"Extras": [
"extraId": 5,
"objId": "PxDQX3LGU2",
"extraName": "ExtraShot",
"extraPrice": 5,
"currency": "Aed",
"isEnabled": 1
]
I'm using the code below to get the modified EditText
values in that
for(int i=0; i < allEds.size(); i++)
pricelist.add(allEds.get(i).getText().toString().trim());
priceidslist.add(allEds.get(i).getId());
This is nested array function here in loop I'm getting array index0,1,2,0,1,2,0 like this i have all editetxt prices list by using im not able to update index position values mismatching
public void jsonarray(JSONArray arry)
try
for (int j = 0; j < arry.length(); j++)
JSONObject rw = arry.getJSONObject(j);
String extraId = rw.optString("extraId");
String objId = rw.optString("objId");
String extraName = rw.optString("extraName");
String extraPrice = rw.optString("extraPrice");
String currenc = rw.optString("currency");
String chksts = rw.optString("isEnabled");
if (namechklist.contains(extraName))
rw.put("isEnabled", "1");
if (nameunchklist.contains(extraName))
rw.put("isEnabled", "0");
if(allnames.contains(extraName))
rw.put("extraPrice", pricelist.get(j));
Log.d("res", "jsonarray:loop "+arry.toString());
Log.d("res", "jsonarray: "+arry.toString());
catch (JSONException e)
e.printStackTrace();
Anyone please suggest me which way is better to achieve this logic correctly
android
This is my json data I have created ui design using this json string but by the time of updating I am confused about this how to correctly get EditText
values and how to update
"SingleExtras": [
"Id": 1,
"name": "size",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "Gb39Rpmdl9",
"extraName": "Small",
"extraPrice": 15,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 30,
"objId": "kknwBtS9zJ",
"extraName": "Medium",
"extraPrice": 18,
"currency": "Aed",
"isEnabled": 0
,
"extraId": 30,
"objId": "d5YfEGAgMt",
"extraName": "Large",
"extraPrice": 20,
"currency": "Aed",
"isEnabled": 1
]
,
"Id": 5,
"name": "Milk",
"isEnabled": 1,
"values": [
"extraId": 30,
"objId": "8obBCWDXbh",
"extraName": "LowFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
,
"extraId": 31,
"objId": "CC629INXuP",
"extraName": "FullFatMilk",
"extraPrice": 0,
"currency": "Aed",
"isEnabled": 1
]
],
"Extras": [
"extraId": 5,
"objId": "PxDQX3LGU2",
"extraName": "ExtraShot",
"extraPrice": 5,
"currency": "Aed",
"isEnabled": 1
]
I'm using the code below to get the modified EditText
values in that
for(int i=0; i < allEds.size(); i++)
pricelist.add(allEds.get(i).getText().toString().trim());
priceidslist.add(allEds.get(i).getId());
This is nested array function here in loop I'm getting array index0,1,2,0,1,2,0 like this i have all editetxt prices list by using im not able to update index position values mismatching
public void jsonarray(JSONArray arry)
try
for (int j = 0; j < arry.length(); j++)
JSONObject rw = arry.getJSONObject(j);
String extraId = rw.optString("extraId");
String objId = rw.optString("objId");
String extraName = rw.optString("extraName");
String extraPrice = rw.optString("extraPrice");
String currenc = rw.optString("currency");
String chksts = rw.optString("isEnabled");
if (namechklist.contains(extraName))
rw.put("isEnabled", "1");
if (nameunchklist.contains(extraName))
rw.put("isEnabled", "0");
if(allnames.contains(extraName))
rw.put("extraPrice", pricelist.get(j));
Log.d("res", "jsonarray:loop "+arry.toString());
Log.d("res", "jsonarray: "+arry.toString());
catch (JSONException e)
e.printStackTrace();
Anyone please suggest me which way is better to achieve this logic correctly
android
android
edited Mar 24 at 3:01
Ahmad
47.1k1597124
47.1k1597124
asked Mar 24 at 2:42
VenkateshVenkatesh
8141023
8141023
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
for (int i = 0; i < jsonArray.length(); i++)
JSONObject row = jsonArray.getJSONObject(i);
String itemid = row.optString("id");
JSONArray arry = row.getJSONArray("values");
if(i == 0)
else
final int ar = arry.length();
final int tot = g + ar ;
int h = 0;
for (int j = g ; j < tot; j++)
JSONObject rw = arry.getJSONObject(h);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(namechklist.size() > 0)
if(namechklist.contains(extraName))
rw.put("isEnabled","1");
if(nameunchklist.size()>0)
if(nameunchklist.contains(extraName))
rw.put("isEnabled","0");
if(j >= arry.length())
else
String gh = String.valueOf(priceidslist.get(j));
if(gh.equals(extraId))
rw.put("extraPrice",pricelist.get(j));
h++;
g = arry.length();
Log.d("chk", "res:last "+jsonArray.toString());
}
JSONArray extraArray = obj.getJSONArray("Extras");
for (int i = 0; i < extraArray.length(); i++)
JSONObject rw = extraArray.getJSONObject(i);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(exnamechklist.size() > 0)
if(exnamechklist.contains(extraName))
rw.put("isEnabled","1");
if(exnameunchklist.size()>0)
if(exnameunchklist.contains(extraName))
rw.put("isEnabled","0");
I just changed for loop condition and changed format of getting json values now its working fine
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320291%2fhow-to-update-dynamic-editext-values-into-nested-json-array-in-android%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
for (int i = 0; i < jsonArray.length(); i++)
JSONObject row = jsonArray.getJSONObject(i);
String itemid = row.optString("id");
JSONArray arry = row.getJSONArray("values");
if(i == 0)
else
final int ar = arry.length();
final int tot = g + ar ;
int h = 0;
for (int j = g ; j < tot; j++)
JSONObject rw = arry.getJSONObject(h);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(namechklist.size() > 0)
if(namechklist.contains(extraName))
rw.put("isEnabled","1");
if(nameunchklist.size()>0)
if(nameunchklist.contains(extraName))
rw.put("isEnabled","0");
if(j >= arry.length())
else
String gh = String.valueOf(priceidslist.get(j));
if(gh.equals(extraId))
rw.put("extraPrice",pricelist.get(j));
h++;
g = arry.length();
Log.d("chk", "res:last "+jsonArray.toString());
}
JSONArray extraArray = obj.getJSONArray("Extras");
for (int i = 0; i < extraArray.length(); i++)
JSONObject rw = extraArray.getJSONObject(i);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(exnamechklist.size() > 0)
if(exnamechklist.contains(extraName))
rw.put("isEnabled","1");
if(exnameunchklist.size()>0)
if(exnameunchklist.contains(extraName))
rw.put("isEnabled","0");
I just changed for loop condition and changed format of getting json values now its working fine
add a comment |
for (int i = 0; i < jsonArray.length(); i++)
JSONObject row = jsonArray.getJSONObject(i);
String itemid = row.optString("id");
JSONArray arry = row.getJSONArray("values");
if(i == 0)
else
final int ar = arry.length();
final int tot = g + ar ;
int h = 0;
for (int j = g ; j < tot; j++)
JSONObject rw = arry.getJSONObject(h);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(namechklist.size() > 0)
if(namechklist.contains(extraName))
rw.put("isEnabled","1");
if(nameunchklist.size()>0)
if(nameunchklist.contains(extraName))
rw.put("isEnabled","0");
if(j >= arry.length())
else
String gh = String.valueOf(priceidslist.get(j));
if(gh.equals(extraId))
rw.put("extraPrice",pricelist.get(j));
h++;
g = arry.length();
Log.d("chk", "res:last "+jsonArray.toString());
}
JSONArray extraArray = obj.getJSONArray("Extras");
for (int i = 0; i < extraArray.length(); i++)
JSONObject rw = extraArray.getJSONObject(i);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(exnamechklist.size() > 0)
if(exnamechklist.contains(extraName))
rw.put("isEnabled","1");
if(exnameunchklist.size()>0)
if(exnameunchklist.contains(extraName))
rw.put("isEnabled","0");
I just changed for loop condition and changed format of getting json values now its working fine
add a comment |
for (int i = 0; i < jsonArray.length(); i++)
JSONObject row = jsonArray.getJSONObject(i);
String itemid = row.optString("id");
JSONArray arry = row.getJSONArray("values");
if(i == 0)
else
final int ar = arry.length();
final int tot = g + ar ;
int h = 0;
for (int j = g ; j < tot; j++)
JSONObject rw = arry.getJSONObject(h);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(namechklist.size() > 0)
if(namechklist.contains(extraName))
rw.put("isEnabled","1");
if(nameunchklist.size()>0)
if(nameunchklist.contains(extraName))
rw.put("isEnabled","0");
if(j >= arry.length())
else
String gh = String.valueOf(priceidslist.get(j));
if(gh.equals(extraId))
rw.put("extraPrice",pricelist.get(j));
h++;
g = arry.length();
Log.d("chk", "res:last "+jsonArray.toString());
}
JSONArray extraArray = obj.getJSONArray("Extras");
for (int i = 0; i < extraArray.length(); i++)
JSONObject rw = extraArray.getJSONObject(i);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(exnamechklist.size() > 0)
if(exnamechklist.contains(extraName))
rw.put("isEnabled","1");
if(exnameunchklist.size()>0)
if(exnameunchklist.contains(extraName))
rw.put("isEnabled","0");
I just changed for loop condition and changed format of getting json values now its working fine
for (int i = 0; i < jsonArray.length(); i++)
JSONObject row = jsonArray.getJSONObject(i);
String itemid = row.optString("id");
JSONArray arry = row.getJSONArray("values");
if(i == 0)
else
final int ar = arry.length();
final int tot = g + ar ;
int h = 0;
for (int j = g ; j < tot; j++)
JSONObject rw = arry.getJSONObject(h);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(namechklist.size() > 0)
if(namechklist.contains(extraName))
rw.put("isEnabled","1");
if(nameunchklist.size()>0)
if(nameunchklist.contains(extraName))
rw.put("isEnabled","0");
if(j >= arry.length())
else
String gh = String.valueOf(priceidslist.get(j));
if(gh.equals(extraId))
rw.put("extraPrice",pricelist.get(j));
h++;
g = arry.length();
Log.d("chk", "res:last "+jsonArray.toString());
}
JSONArray extraArray = obj.getJSONArray("Extras");
for (int i = 0; i < extraArray.length(); i++)
JSONObject rw = extraArray.getJSONObject(i);
String extraName = rw.optString("extraName");
String extraId = rw.optString("extraId");
if(exnamechklist.size() > 0)
if(exnamechklist.contains(extraName))
rw.put("isEnabled","1");
if(exnameunchklist.size()>0)
if(exnameunchklist.contains(extraName))
rw.put("isEnabled","0");
I just changed for loop condition and changed format of getting json values now its working fine
answered Mar 26 at 10:19
VenkateshVenkatesh
8141023
8141023
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320291%2fhow-to-update-dynamic-editext-values-into-nested-json-array-in-android%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown