我有一个 json 文件,我需要解析它并从中获取一些字符串,托管 C++ (c++/cli) 中是否有任何代码或示例,谢谢。 这是我的 json 文件的摘录,我需要获取所有节点
{ "ID": "{15DFD536-EC23-4624-803E-5AA719DC7A85}", "节点": [ -0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0, -0.01, 0.01 ]}
最佳答案
这是使用 Json.NET 的示例:
#include "stdafx.h"
using namespace System;
using namespace Newtonsoft::Json;
ref class MyData
{
public: Guid ID;
public: array<double>^ Nodes;
};
int main(array<System::String ^> ^args)
{
String^ json = "{ \"ID\": \"{15DFD536-EC23-4624-803E-5AA719DC7A85}\", \"Nodes\": [ -0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0, -0.01, 0.01 ]}";
MyData^ data = JsonConvert::DeserializeObject<MyData^>(json);
Console::WriteLine("ID: {0}\nNodes: {1}", data->ID, String::Join(",", System::Linq::Enumerable::Cast<Object^>(data->Nodes)));
return 0;
}
结果:
ID: 15dfd536-ec23-4624-803e-5aa719dc7a85
Nodes: -0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0,-0.01,0.01
关于c++-cli - 从 JSON 文件 c/cli 获取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165604/