Created
August 28, 2018 23:12
-
-
Save mojeld/5b63d4083703d9693f22a05639b8cae4 to your computer and use it in GitHub Desktop.
JSON analysis with UWP VC++2017.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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