欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

c 讀取csv json.net

CSV(Comma Separated Values)是一種簡(jiǎn)單的文件格式,常用于存儲(chǔ)表格數(shù)據(jù),每行數(shù)據(jù)用逗號(hào)隔開(kāi)。C語(yǔ)言讀取CSV文件可以使用fscanf等函數(shù),但是需要解析字符串并轉(zhuǎn)換為對(duì)應(yīng)的數(shù)據(jù)類(lèi)型。

FILE *fp;
double value;
char line[1024];
char *token;
fp = fopen("data.csv", "r");
if (fp != NULL) {
while (fgets(line, sizeof(line), fp) != NULL) {
token = strtok(line, ",");
while (token != NULL) {
sscanf(token, "%lf", &value);
printf("%f ", value);
token = strtok(NULL, ",");
}
}
fclose(fp);
}

Json.NET是一個(gè)流行的JSON處理庫(kù),它可以方便地將JSON數(shù)據(jù)轉(zhuǎn)換為對(duì)象。

string json = @"{
'name': 'John Doe',
'age': 30,
'address': {
'street': '123 Main St.',
'city': 'Anytown',
'state': 'USA'
},
'phone': [
{
'type': 'home',
'number': '555-555-1234'
},
{
'type': 'work',
'number': '555-555-5678'
}
]
}";
JObject jsonObject = JObject.Parse(json);
string name = (string)jsonObject["name"];
int age = (int)jsonObject["age"];
JObject address = (JObject)jsonObject["address"];
string street = (string)address["street"];
JArray phone = (JArray)jsonObject["phone"];
foreach (JObject item in phone) {
string type = (string)item["type"];
string number = (string)item["number"];
}