How do I insert statements inside Newtonsoft.JSON codes
How do I insert statements inside Newtonsoft.JSON codes
So basically I wanted to do:
json code,
statement,
when statement is true,some other json text
continuation of previous json code
This is currently my code and I'm looking a way to shorten it, any solutions?
if (textBox1.Text != "Enter Address")
if (textBox2.Text != "Enter Address")
//1+2+3 OK
if (textBox3.Text != "Enter Address")
var item = new Item
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
path = textBox4.Text
,
music_preview = new ItemMusicPreview
path = textBox5.Text
,
background = new ItemBackground
path = open3.SafeFileName
,
charts = new List<ItemChart>
new ItemChart
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
,
new ItemChart
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
,
new ItemChart
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
;
var settings = new JsonSerializerSettings()
ContractResolver = new DefaultContractResolver
NamingStrategy = new SnakeCaseNamingStrategy()
;
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:UsersPublicDesktoplevel files") == false)
// Make a path
System.IO.Directory.CreateDirectory(@"C:UsersPublicDesktoplevel files");
if (File.Exists($@"C:UsersPublicDesktoplevel filestextBox14.Text") == false)
// Make a path
System.IO.Directory.CreateDirectory($@"C:UsersPublicDesktoplevel filestextBox14.Text");
File.WriteAllText($@"C:UsersPublicDesktoplevel filestextBox14.Textlevel.json", json, new UTF8Encoding(false));
//1+2 (3) OK
else
var item = new Item
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
path = textBox4.Text
,
music_preview = new ItemMusicPreview
path = textBox5.Text
,
background = new ItemBackground
path = open3.SafeFileName
,
charts = new List<ItemChart>
new ItemChart
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
,
new ItemChart
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
;
var settings = new JsonSerializerSettings()
ContractResolver = new DefaultContractResolver
NamingStrategy = new SnakeCaseNamingStrategy()
;
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:UsersPublicDesktoplevel files") == false)
// Make a path
System.IO.Directory.CreateDirectory(@"C:UsersPublicDesktoplevel files");
if (File.Exists($@"C:UsersPublicDesktoplevel filestextBox14.Text") == false)
// Make a path
System.IO.Directory.CreateDirectory($@"C:UsersPublicDesktoplevel filestextBox14.Text");
File.WriteAllText($@"C:UsersPublicDesktoplevel filestextBox14.Textlevel.json", json, new UTF8Encoding(false));
else
//1+3 (2) OK
if (textBox3.Text != "Enter Address")
var item = new Item
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
path = textBox4.Text
,
music_preview = new ItemMusicPreview
path = textBox5.Text
,
background = new ItemBackground
path = open3.SafeFileName
,
charts = new List<ItemChart>
new ItemChart
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
,
new ItemChart
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
;
var settings = new JsonSerializerSettings()
ContractResolver = new DefaultContractResolver
NamingStrategy = new SnakeCaseNamingStrategy()
;
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:UsersPublicDesktoplevel files") == false)
// Make a path
System.IO.Directory.CreateDirectory(@"C:UsersPublicDesktoplevel files");
if (File.Exists($@"C:UsersPublicDesktoplevel filestextBox14.Text") == false)
// Make a path
System.IO.Directory.CreateDirectory($@"C:UsersPublicDesktoplevel filestextBox14.Text");
File.WriteAllText($@"C:UsersPublicDesktoplevel filestextBox14.Textlevel.json", json, new UTF8Encoding(false));
//1 (2)(3) OK
else
var item = new Item
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
path = textBox4.Text
,
music_preview = new ItemMusicPreview
path = textBox5.Text
,
background = new ItemBackground
path = open3.SafeFileName
,
charts = new List<ItemChart>
new ItemChart
type = "easy",
name = textBox15.Text,
difficulty = Convert.ToInt32(numericUpDown1.Value),
path = textBox1.Text
;
var settings = new JsonSerializerSettings()
ContractResolver = new DefaultContractResolver
NamingStrategy = new SnakeCaseNamingStrategy()
;
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:UsersPublicDesktoplevel files") == false)
// Make a path
System.IO.Directory.CreateDirectory(@"C:UsersPublicDesktoplevel files");
if (File.Exists($@"C:UsersPublicDesktoplevel filestextBox14.Text") == false)
// Make a path
System.IO.Directory.CreateDirectory($@"C:UsersPublicDesktoplevel filestextBox14.Text");
File.WriteAllText($@"C:UsersPublicDesktoplevel filestextBox14.Textlevel.json", json, new UTF8Encoding(false));
else
if (textBox2.Text != "Enter Address")
//2+3 (1) OK
if (textBox3.Text != "Enter Address")
var item = new Item
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
path = textBox4.Text
,
music_preview = new ItemMusicPreview
path = textBox5.Text
,
background = new ItemBackground
path = open3.SafeFileName
,
charts = new List<ItemChart>
new ItemChart
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
,
new ItemChart
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
;
var settings = new JsonSerializerSettings()
ContractResolver = new DefaultContractResolver
NamingStrategy = new SnakeCaseNamingStrategy()
;
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:UsersPublicDesktoplevel files") == false)
// Make a path
System.IO.Directory.CreateDirectory(@"C:UsersPublicDesktoplevel files");
if (File.Exists($@"C:UsersPublicDesktoplevel filestextBox14.Text") == false)
// Make a path
System.IO.Directory.CreateDirectory($@"C:UsersPublicDesktoplevel filestextBox14.Text");
File.WriteAllText($@"C:UsersPublicDesktoplevel filestextBox14.Textlevel.json", json, new UTF8Encoding(false));
//2 (1)(3)
else
var item = new Item
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
path = textBox4.Text
,
music_preview = new ItemMusicPreview
path = textBox5.Text
,
background = new ItemBackground
path = open3.SafeFileName
,
charts = new List<ItemChart>
new ItemChart
type = "hard",
name = textBox16.Text,
difficulty = Convert.ToInt32(numericUpDown2.Value),
path = textBox2.Text
;
var settings = new JsonSerializerSettings()
ContractResolver = new DefaultContractResolver
NamingStrategy = new SnakeCaseNamingStrategy()
;
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:UsersPublicDesktoplevel files") == false)
// Make a path
System.IO.Directory.CreateDirectory(@"C:UsersPublicDesktoplevel files");
if (File.Exists($@"C:UsersPublicDesktoplevel filestextBox14.Text") == false)
// Make a path
System.IO.Directory.CreateDirectory($@"C:UsersPublicDesktoplevel filestextBox14.Text");
File.WriteAllText($@"C:UsersPublicDesktoplevel filestextBox14.Textlevel.json", json, new UTF8Encoding(false));
else
var item = new Item
version = 1,
schema_version = 2,
id = textBox14.Text,
title = textBox7.Text,
title_localized = textBox18.Text,
artist = textBox6.Text,
artist_localized = textBox8.Text,
artist_source = textBox9.Text,
illustrator = textBox10.Text,
illustrator_source = textBox11.Text,
charter = textBox13.Text,
music = new ItemMusic
path = textBox4.Text
,
music_preview = new ItemMusicPreview
path = textBox5.Text
,
background = new ItemBackground
path = open3.SafeFileName
,
charts = new List<ItemChart>
new ItemChart
type = "extreme",
name = textBox17.Text,
difficulty = Convert.ToInt32(numericUpDown3.Value),
path = textBox3.Text
,
;
var settings = new JsonSerializerSettings()
ContractResolver = new DefaultContractResolver
NamingStrategy = new SnakeCaseNamingStrategy()
;
var json = JsonConvert.SerializeObject(item, settings);
if (File.Exists(@"C:UsersPublicDesktoplevel files") == false)
// Make a path
System.IO.Directory.CreateDirectory(@"C:UsersPublicDesktoplevel files");
if (File.Exists($@"C:UsersPublicDesktoplevel filestextBox14.Text") == false)
// Make a path
System.IO.Directory.CreateDirectory($@"C:UsersPublicDesktoplevel filestextBox14.Text");
File.WriteAllText($@"C:UsersPublicDesktoplevel filestextBox14.Textlevel.json", json, new UTF8Encoding(false));
I was going to add "storyboard = open9.FileName" to "new ItemChart"s but not add the storyboard line when the file address is not imported.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.