如何在asp.net MVC 5中获取缩进的JSON输出以在浏览器中查看?

时间:2016-06-04 08:10:52

标签: json asp.net-mvc

这仅用于调试目的。只返回JSON,在网页上输出不可读的JSON字符串。是否有任何快速解决方案可以在网页上查看格式化的json?

寻找一个C#函数,该函数将从我的action方法中获取json对象并将格式化输出作为字符串返回。

2 个答案:

答案 0 :(得分:1)

使用JavaScript Ld /Users/7stud/Library/Developer/Xcode/DerivedData/FirebaseApplicationExample-ewixbbawksqkuaaqeeobeaexeirc/Build/Products/Debug-iphonesimulator/FirebaseApplicationExample.app/FirebaseApplicationExample normal x86_64 cd /Users/7stud/xcode_projects/iOS/FirebaseApplicationExample export IPHONEOS_DEPLOYMENT_TARGET=9.2 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk -L/Users/7stud/Library/Developer/Xcode/DerivedData/FirebaseApplicationExample-ewixbbawksqkuaaqeeobeaexeirc/Build/Products/Debug-iphonesimulator -F/Users/7stud/Library/Developer/Xcode/DerivedData/FirebaseApplicationExample-ewixbbawksqkuaaqeeobeaexeirc/Build/Products/Debug-iphonesimulator -F/Users/7stud/xcode_projects/iOS/FirebaseApplicationExample/FirebaseApplicationExample -filelist /Users/7stud/Library/Developer/Xcode/DerivedData/FirebaseApplicationExample-ewixbbawksqkuaaqeeobeaexeirc/Build/Intermediates/FirebaseApplicationExample.build/Debug-iphonesimulator/FirebaseApplicationExample.build/Objects-normal/x86_64/FirebaseApplicationExample.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.2 -Xlinker -objc_abi_version -Xlinker 2 -ObjC -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/7stud/Library/Developer/Xcode/DerivedData/FirebaseApplicationExample-ewixbbawksqkuaaqeeobeaexeirc/Build/Intermediates/FirebaseApplicationExample.build/Debug-iphonesimulator/FirebaseApplicationExample.build/Objects-normal/x86_64/FirebaseApplicationExample.swiftmodule -framework FirebaseDatabase -framework GoogleInterchangeUtilities -framework FirebaseAnalytics -framework GoogleSymbolUtilities -framework GoogleUtilities -framework FirebaseInstanceID -Xlinker -dependency_info -Xlinker /Users/7stud/Library/Developer/Xcode/DerivedData/FirebaseApplicationExample-ewixbbawksqkuaaqeeobeaexeirc/Build/Intermediates/FirebaseApplicationExample.build/Debug-iphonesimulator/FirebaseApplicationExample.build/Objects-normal/x86_64/FirebaseApplicationExample_dependency_info.dat -o /Users/7stud/Library/Developer/Xcode/DerivedData/FirebaseApplicationExample-ewixbbawksqkuaaqeeobeaexeirc/Build/Products/Debug-iphonesimulator/FirebaseApplicationExample.app/FirebaseApplicationExample Undefined symbols for architecture x86_64: "_ABAddressBookAddRecord", referenced from: -[GSDK_GTMABAddressBook addRecord:] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookCopyArrayOfAllGroups", referenced from: -[GSDK_GTMABAddressBook groups] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookCopyArrayOfAllPeople", referenced from: -[GSDK_GTMABAddressBook people] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookCopyLocalizedLabel", referenced from: +[GSDK_GTMABAddressBook localizedLabel:] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookCopyPeopleWithName", referenced from: -[GSDK_GTMABAddressBook peopleWithCompositeNameWithPrefix:] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookCreateWithOptions", referenced from: -[GSDK_GTMABAddressBook init] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookGetGroupWithRecordID", referenced from: -[GSDK_GTMABAddressBook groupForId:] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookGetPersonWithRecordID", referenced from: -[GSDK_GTMABAddressBook personForId:] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookHasUnsavedChanges", referenced from: -[GSDK_GTMABAddressBook hasUnsavedChanges] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookRemoveRecord", referenced from: -[GSDK_GTMABAddressBook removeRecord:] in GoogleUtilities(GTMABAddressBook.o) "_ABAddressBookSave", referenced from: -[GSDK_GTMABAddressBook save] in GoogleUtilities(GTMABAddressBook.o) "_ABGroupAddMember", referenced from: -[GSDK_GTMABGroup addMember:] in GoogleUtilities(GTMABAddressBook.o) "_ABGroupCopyArrayOfAllMembers", referenced from: -[GSDK_GTMABGroup members] in GoogleUtilities(GTMABAddressBook.o) "_ABGroupCreate", referenced from: -[GSDK_GTMABGroup init] in GoogleUtilities(GTMABAddressBook.o) "_ABGroupRemoveMember", referenced from: -[GSDK_GTMABGroup removeMember:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueAddValueAndLabel", referenced from: -[GSDK_GTMABMutableMultiValue addValue:withLabel:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueCopyLabelAtIndex", referenced from: -[GSDK_GTMABMultiValue labelAtIndex:] in GoogleUtilities(GTMABAddressBook.o) -[GSDK_GTMABMultiValueEnumerator nextObject] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueCopyValueAtIndex", referenced from: -[GSDK_GTMABMultiValue valueAtIndex:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueCreateMutable", referenced from: -[GSDK_GTMABMutableMultiValue initWithPropertyType:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueCreateMutableCopy", referenced from: -[GSDK_GTMABMutableMultiValue initWithMultiValue:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueGetCount", referenced from: -[GSDK_GTMABMultiValue count] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueGetIdentifierAtIndex", referenced from: -[GSDK_GTMABMultiValue identifierAtIndex:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueGetIndexForIdentifier", referenced from: -[GSDK_GTMABMultiValue indexForIdentifier:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueGetPropertyType", referenced from: -[GSDK_GTMABMultiValue propertyType] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueInsertValueAndLabelAtIndex", referenced from: -[GSDK_GTMABMutableMultiValue insertValue:withLabel:atIndex:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueRemoveValueAndLabelAtIndex", referenced from: -[GSDK_GTMABMutableMultiValue removeValueAndLabelAtIndex:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueReplaceLabelAtIndex", referenced from: -[GSDK_GTMABMutableMultiValue replaceLabelAtIndex:withLabel:] in GoogleUtilities(GTMABAddressBook.o) "_ABMultiValueReplaceValueAtIndex", referenced from: -[GSDK_GTMABMutableMultiValue replaceValueAtIndex:withValue:] in GoogleUtilities(GTMABAddressBook.o) "_ABPersonCopyImageData", referenced from: -[GSDK_GTMABPerson imageData] in GoogleUtilities(GTMABAddressBook.o) "_ABPersonCopyLocalizedPropertyName", referenced from: +[GSDK_GTMABPerson localizedPropertyName:] in GoogleUtilities(GTMABAddressBook.o) "_ABPersonCreate", referenced from: -[GSDK_GTMABPerson init] in GoogleUtilities(GTMABAddressBook.o) "_ABPersonGetCompositeNameFormat", referenced from: +[GSDK_GTMABPerson compositeNameFormat] in GoogleUtilities(GTMABAddressBook.o) "_ABPersonGetTypeOfProperty", referenced from: +[GSDK_GTMABPerson typeOfProperty:] in GoogleUtilities(GTMABAddressBook.o) "_ABPersonRemoveImageData", referenced from: -[GSDK_GTMABPerson setImageData:] in GoogleUtilities(GTMABAddressBook.o) "_ABPersonSetImageData", referenced from: -[GSDK_GTMABPerson setImageData:] in GoogleUtilities(GTMABAddressBook.o) "_ABRecordCopyCompositeName", referenced from: -[GSDK_GTMABPerson compositeName] in GoogleUtilities(GTMABAddressBook.o) -[GSDK_GTMABGroup compositeName] in GoogleUtilities(GTMABAddressBook.o) "_ABRecordCopyValue", referenced from: -[GSDK_GTMABRecord valueForProperty:] in GoogleUtilities(GTMABAddressBook.o) "_ABRecordGetRecordID", referenced from: -[GSDK_GTMABRecord recordID] in GoogleUtilities(GTMABAddressBook.o) "_ABRecordRemoveValue", referenced from: -[GSDK_GTMABRecord removeValueForProperty:] in GoogleUtilities(GTMABAddressBook.o) "_ABRecordSetValue", referenced from: -[GSDK_GTMABRecord setValue:forProperty:] in GoogleUtilities(GTMABAddressBook.o) "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from: leveldb::VersionSet::Recover() in FirebaseDatabase(version_set.o) "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from: void std::__1::vector<std::__1::pair<int, leveldb::FileMetaData>, std::__1::allocator<std::__1::pair<int, leveldb::FileMetaData> > >::__push_back_slow_path<std::__1::pair<int, leveldb::FileMetaData> const>(std::__1::pair<int, leveldb::FileMetaData> const&) in FirebaseDatabase(db_impl.o) void std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long> >::__push_back_slow_path<unsigned long long const>(unsigned long long const&) in FirebaseDatabase(db_impl.o) void std::__1::vector<leveldb::DBImpl::CompactionState::Output, std::__1::allocator<leveldb::DBImpl::CompactionState::Output> >::__push_back_slow_path<leveldb::DBImpl::CompactionState::Output const>(leveldb::DBImpl::CompactionState::Output const&) in FirebaseDatabase(db_impl.o) void std::__1::vector<leveldb::Iterator*, std::__1::allocator<leveldb::Iterator*> >::__push_back_slow_path<leveldb::Iterator* const>(leveldb::Iterator* const&) in FirebaseDatabase(db_impl.o) ... ... "_utf8_nextCharSafeBody", referenced from: -[FSRWebSocket _innerPumpScanner] in FirebaseDatabase(FSRWebSocket.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Showing first 200 notices only 功能。例如:

JSON.Stringify()

答案 1 :(得分:1)

只需更改Global.asax文件中的JSON全局设置。

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
{
    Formatting = Formatting.Indented
};

它应该为所有Web API端点生成缩进的JSON。

然后,您可以直接在浏览器中检查生成的JSON,或使用像Fiddler这样的HTTP流量捕获工具。