JSON.Net获取本机类型的值

时间:2015-02-17 14:59:51

标签: c# json types json.net

使用JSON.Net,如何在JSON文件中获取本机类型的值?也就是说,我只是在它之后是否是一个字符串(括在引号中的值)。

var json = (JObject) JsonConvert.DeserializeObject(newVersion.JSON);
foreach (var data in json)
{
    if(data.value IS STRING){

    }
}

2 个答案:

答案 0 :(得分:5)

您只需查看列表中每个Type的{​​{1}}属性:

JToken

请参阅JTokenType

答案 1 :(得分:1)

您可以参考此answer

通过

解析json字符串
<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx'); 

使用JToken标识其类型,

[Thu Dec 06 21:14:42.835498 2018] [:error] [pid 1582] [client 192.168.223.1:53200] PHP Warning:  require(vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/custom/excel.php on line 3
[Thu Dec 06 21:14:42.835716 2018] [:error] [pid 1582] [client 192.168.223.1:53200] PHP Fatal error:  require(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/html/custom/excel.php on line 3