我已经阅读了一段时间现在该怎么做,但我从来没有找到我理解或工作的芒果。
这是我的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
namespace SongTunes
{
public partial class Form1 : Form
{
Object Songs;
public class Song
{
public int song_id { get { return song_id; } set { song_id = value; } }
public string sorting_number { get; set; }
public string name { get; set; }
public string description { get; set; }
public string lyrics { get; set; }
public string purchase_link { get; set; }
public string youtube_id { get; set; }
public string has_music_video { get; set; }
public string allow_downloads { get; set; }
public string raw_artist_id { get; set; }
public string artist_id { get; set; }
public string album_artist_id { get; set; }
public string release_date { get; set; }
public string artist_name { get; set; }
public string album_artist_name { get; set; }
public string album { get; set; }
public string bitrate { get; set; }
public string duration { get; set; }
public string filesize { get; set; }
public string path { get; set; }
public string is_part_of_compilation { get; set; }
public string visible { get; set; }
public string track_number { get; set; }
public string is_explicit { get; set; }
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button1.Text = "Loading...";
backgroundWorker1.RunWorkerAsync();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void backgroundWorker1_Done(object sender, RunWorkerCompletedEventArgs e)
{
button1.Enabled = true;
button1.Text = "reload";
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string address = "";
System.Net.WebClient webclient = new WebClient();
string json = webclient.DownloadString(address);
Songs = JsonConvert.DeserializeObject<List<Song>>(json);
}
private void SongList_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
它只是在第一次
崩溃public int song_id { get { return song_id; } set { song_id = value; } }
“在SongTunes.exe中发生了'System.StackOverflowException'类型的未处理异常”
答案 0 :(得分:4)
public int song_id { get { return song_id; } set { song_id = value; } }
get和引用它自己,这会在你调用它时导致堆栈溢出。如果要将值保存在字段中,请尝试:
private int _song_id;
public int song_id { get { return _song_id; } set { _song_id = value; } }
或只是将其更改为:
public int song_id { get; set; }
与您的其他属性一样