Instantly share code, notes, and snippets.

Embed
What would you like to do?
JSON analysis with UWP VC++2017.
//
// JSON analysis using UWP's JsonObject
//
void cpp_uwp::json_test::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
using namespace Windows::Data::Json;
std::function<void(JsonObject^)> hhge{ [this](JsonObject^ json1) {
std::wstringstream lout;
std::function<void(IJsonValue^, Platform::String^)> foo{
[this, &foo, &lout](IJsonValue^ ijv1, Platform::String^ key_name) {
int i;
Platform::String^ s;
switch (ijv1->ValueType)
{
case JsonValueType::Boolean:
lout << key_name->Data() << "," << (ijv1->GetBoolean() ? L"true" : L"false") << std::endl;
break;
case JsonValueType::Array:
for (int i1 = 0; i1 < ijv1->GetArray()->Size; ++i1)
{
foo(ijv1->GetArray()->GetAt(i1), key_name);
}
break;
case JsonValueType::Number:
i = ijv1->GetNumber();
lout << key_name->Data() << "," << i << std::endl;
break;
case JsonValueType::String:
s = ijv1->GetString();
lout << key_name->Data() << "," << s->Data() << std::endl;
break;
case JsonValueType::Object:
bool bNext{true};
auto JIt1 = ((JsonValue^)ijv1)->GetObject()->First();
while (bNext)
{
foo(JIt1->Current->Value, JIt1->Current->Key);
bNext = JIt1->MoveNext();
}
break;
}
} };
foo(json1, nullptr);
std::wstring outp{lout.str()};
Edit1->Text = ref new Platform::String(outp.c_str());
} };
hhge(JsonObject::Parse(Edit1->Text));//文字列JSONの解析
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment