Skip to content

Instantly share code, notes, and snippets.

@mojeld
Created August 28, 2018 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mojeld/5b63d4083703d9693f22a05639b8cae4 to your computer and use it in GitHub Desktop.
Save mojeld/5b63d4083703d9693f22a05639b8cae4 to your computer and use it in GitHub Desktop.
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