How to create json using textviews? android studio












2















i want to create a json like this:



{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}


from my textviews



name = txtName.getText().toString;
id = txtId.getText().toString;


etc



but i do not know how, neither know how the {} are added to json



can someone explain me or tell me an how to create it? thanks










share|improve this question

























  • Use JSONObjects and JSONArrays. Here is a tutorial.

    – Kartik
    Nov 22 '18 at 4:39











  • Welcome to StackOverflow! So, what have you tried?

    – Andreas
    Nov 22 '18 at 4:40











  • @Andreas thank you! nothing yet, I'm a little bit confused

    – hernyval
    Nov 22 '18 at 4:47











  • @Kartik I will check it, thanks!

    – hernyval
    Nov 22 '18 at 4:47











  • Please update once you have tried something. I would suggest to do more Google search first, when you are stuck

    – Andreas
    Nov 22 '18 at 4:48


















2















i want to create a json like this:



{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}


from my textviews



name = txtName.getText().toString;
id = txtId.getText().toString;


etc



but i do not know how, neither know how the {} are added to json



can someone explain me or tell me an how to create it? thanks










share|improve this question

























  • Use JSONObjects and JSONArrays. Here is a tutorial.

    – Kartik
    Nov 22 '18 at 4:39











  • Welcome to StackOverflow! So, what have you tried?

    – Andreas
    Nov 22 '18 at 4:40











  • @Andreas thank you! nothing yet, I'm a little bit confused

    – hernyval
    Nov 22 '18 at 4:47











  • @Kartik I will check it, thanks!

    – hernyval
    Nov 22 '18 at 4:47











  • Please update once you have tried something. I would suggest to do more Google search first, when you are stuck

    – Andreas
    Nov 22 '18 at 4:48
















2












2








2








i want to create a json like this:



{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}


from my textviews



name = txtName.getText().toString;
id = txtId.getText().toString;


etc



but i do not know how, neither know how the {} are added to json



can someone explain me or tell me an how to create it? thanks










share|improve this question
















i want to create a json like this:



{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}


from my textviews



name = txtName.getText().toString;
id = txtId.getText().toString;


etc



but i do not know how, neither know how the {} are added to json



can someone explain me or tell me an how to create it? thanks







java json android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 5:52







hernyval

















asked Nov 22 '18 at 4:32









hernyvalhernyval

135




135













  • Use JSONObjects and JSONArrays. Here is a tutorial.

    – Kartik
    Nov 22 '18 at 4:39











  • Welcome to StackOverflow! So, what have you tried?

    – Andreas
    Nov 22 '18 at 4:40











  • @Andreas thank you! nothing yet, I'm a little bit confused

    – hernyval
    Nov 22 '18 at 4:47











  • @Kartik I will check it, thanks!

    – hernyval
    Nov 22 '18 at 4:47











  • Please update once you have tried something. I would suggest to do more Google search first, when you are stuck

    – Andreas
    Nov 22 '18 at 4:48





















  • Use JSONObjects and JSONArrays. Here is a tutorial.

    – Kartik
    Nov 22 '18 at 4:39











  • Welcome to StackOverflow! So, what have you tried?

    – Andreas
    Nov 22 '18 at 4:40











  • @Andreas thank you! nothing yet, I'm a little bit confused

    – hernyval
    Nov 22 '18 at 4:47











  • @Kartik I will check it, thanks!

    – hernyval
    Nov 22 '18 at 4:47











  • Please update once you have tried something. I would suggest to do more Google search first, when you are stuck

    – Andreas
    Nov 22 '18 at 4:48



















Use JSONObjects and JSONArrays. Here is a tutorial.

– Kartik
Nov 22 '18 at 4:39





Use JSONObjects and JSONArrays. Here is a tutorial.

– Kartik
Nov 22 '18 at 4:39













Welcome to StackOverflow! So, what have you tried?

– Andreas
Nov 22 '18 at 4:40





Welcome to StackOverflow! So, what have you tried?

– Andreas
Nov 22 '18 at 4:40













@Andreas thank you! nothing yet, I'm a little bit confused

– hernyval
Nov 22 '18 at 4:47





@Andreas thank you! nothing yet, I'm a little bit confused

– hernyval
Nov 22 '18 at 4:47













@Kartik I will check it, thanks!

– hernyval
Nov 22 '18 at 4:47





@Kartik I will check it, thanks!

– hernyval
Nov 22 '18 at 4:47













Please update once you have tried something. I would suggest to do more Google search first, when you are stuck

– Andreas
Nov 22 '18 at 4:48







Please update once you have tried something. I would suggest to do more Google search first, when you are stuck

– Andreas
Nov 22 '18 at 4:48














1 Answer
1






active

oldest

votes


















0














Let's solve via a bottom up approach



1.create detailblog array



JSONObject detailblog1 = new JSONObject();

try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);

} catch (JSONException e) {
e.printStackTrace();
}

JSONObject detailblog2 = new JSONObject();

try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONObject detailblog3 = new JSONObject();

try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONArray jsonArray = new JSONArray();

jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);


2.complete the blog JSONObject



JSONObject blogs= new JSONObject();

try {

blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);

} catch (JSONException e) {
e.printStackTrace();
}


3.complete the blogs JSONObject



JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}

Log.d("json",json.toString());





share|improve this answer


























  • Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?

    – hernyval
    Nov 22 '18 at 20:34











  • @hernyval nice catch, i missed it :)

    – Touhidul Islam
    Nov 23 '18 at 2:02











  • dont worry! thank you, works perfect

    – hernyval
    Nov 23 '18 at 2:09











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423934%2fhow-to-create-json-using-textviews-android-studio%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









0














Let's solve via a bottom up approach



1.create detailblog array



JSONObject detailblog1 = new JSONObject();

try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);

} catch (JSONException e) {
e.printStackTrace();
}

JSONObject detailblog2 = new JSONObject();

try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONObject detailblog3 = new JSONObject();

try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONArray jsonArray = new JSONArray();

jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);


2.complete the blog JSONObject



JSONObject blogs= new JSONObject();

try {

blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);

} catch (JSONException e) {
e.printStackTrace();
}


3.complete the blogs JSONObject



JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}

Log.d("json",json.toString());





share|improve this answer


























  • Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?

    – hernyval
    Nov 22 '18 at 20:34











  • @hernyval nice catch, i missed it :)

    – Touhidul Islam
    Nov 23 '18 at 2:02











  • dont worry! thank you, works perfect

    – hernyval
    Nov 23 '18 at 2:09
















0














Let's solve via a bottom up approach



1.create detailblog array



JSONObject detailblog1 = new JSONObject();

try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);

} catch (JSONException e) {
e.printStackTrace();
}

JSONObject detailblog2 = new JSONObject();

try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONObject detailblog3 = new JSONObject();

try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONArray jsonArray = new JSONArray();

jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);


2.complete the blog JSONObject



JSONObject blogs= new JSONObject();

try {

blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);

} catch (JSONException e) {
e.printStackTrace();
}


3.complete the blogs JSONObject



JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}

Log.d("json",json.toString());





share|improve this answer


























  • Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?

    – hernyval
    Nov 22 '18 at 20:34











  • @hernyval nice catch, i missed it :)

    – Touhidul Islam
    Nov 23 '18 at 2:02











  • dont worry! thank you, works perfect

    – hernyval
    Nov 23 '18 at 2:09














0












0








0







Let's solve via a bottom up approach



1.create detailblog array



JSONObject detailblog1 = new JSONObject();

try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);

} catch (JSONException e) {
e.printStackTrace();
}

JSONObject detailblog2 = new JSONObject();

try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONObject detailblog3 = new JSONObject();

try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONArray jsonArray = new JSONArray();

jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);


2.complete the blog JSONObject



JSONObject blogs= new JSONObject();

try {

blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);

} catch (JSONException e) {
e.printStackTrace();
}


3.complete the blogs JSONObject



JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}

Log.d("json",json.toString());





share|improve this answer















Let's solve via a bottom up approach



1.create detailblog array



JSONObject detailblog1 = new JSONObject();

try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);

} catch (JSONException e) {
e.printStackTrace();
}

JSONObject detailblog2 = new JSONObject();

try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONObject detailblog3 = new JSONObject();

try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}


JSONArray jsonArray = new JSONArray();

jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);


2.complete the blog JSONObject



JSONObject blogs= new JSONObject();

try {

blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);

} catch (JSONException e) {
e.printStackTrace();
}


3.complete the blogs JSONObject



JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}

Log.d("json",json.toString());






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 2:01

























answered Nov 22 '18 at 12:20









Touhidul IslamTouhidul Islam

1,3041415




1,3041415













  • Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?

    – hernyval
    Nov 22 '18 at 20:34











  • @hernyval nice catch, i missed it :)

    – Touhidul Islam
    Nov 23 '18 at 2:02











  • dont worry! thank you, works perfect

    – hernyval
    Nov 23 '18 at 2:09



















  • Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?

    – hernyval
    Nov 22 '18 at 20:34











  • @hernyval nice catch, i missed it :)

    – Touhidul Islam
    Nov 23 '18 at 2:02











  • dont worry! thank you, works perfect

    – hernyval
    Nov 23 '18 at 2:09

















Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?

– hernyval
Nov 22 '18 at 20:34





Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?

– hernyval
Nov 22 '18 at 20:34













@hernyval nice catch, i missed it :)

– Touhidul Islam
Nov 23 '18 at 2:02





@hernyval nice catch, i missed it :)

– Touhidul Islam
Nov 23 '18 at 2:02













dont worry! thank you, works perfect

– hernyval
Nov 23 '18 at 2:09





dont worry! thank you, works perfect

– hernyval
Nov 23 '18 at 2:09




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423934%2fhow-to-create-json-using-textviews-android-studio%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]